tomflynn123
02-18-2009, 12:07 PM
I am a newbie designing a weblog in visual web developer, using a sql server to store all the relevant db's. and Im currently trying to sort out the log in section, and when compiling I get the following error.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
This is the code where the exception is thrown:-
Imports System.Data.Odbc
Imports System.Configuration
Imports System.Web.Security
Public Class Login
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Protected UserName As System.Web.UI.WebControls.TextBox
Protected Password As System.Web.UI.WebControls.TextBox
Protected Persistent As System.Web.UI.WebControls.CheckBox
Protected WithEvents LoginUser As System.Web.UI.WebControls.Button
Protected InvalidLogin As System.Web.UI.WebControls.Label
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
' if the querystring contains a "Action=logout" param, logout and delete the cookie
If Request.Params("Action") = "logout" Then
FormsAuthentication.SignOut()
End If
End If
End Sub
' Protected Sub LoginUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginUser.Click
' check username and password
' If FormsAuthentication.Authenticate(UserName.Text, Password.Text) Then
' if ok, save the cookie
' FormsAuthentication.SetAuthCookie(UserName.Text, Persistent.Checked)
' redirect to Default.aspx
' Response.Redirect("Default.aspx", True)
'Else
' if wrong credentials, show the error message
' InvalidLogin.Visible = True
' End If
'End Sub
Protected Shared Function getConnectionString() As String
'Pass the connectionstring in the appsettings of the web.config file
Return ConfigurationManager.AppSettings("Blog_ConnString")
End Function
Function CreateDataSource(ByVal sql As String) As DataSet
Dim oQRY As String = sql
Dim oDataAdapter As OdbcDataAdapter
Dim oDataSet As DataSet = New DataSet()
oDataAdapter = New OdbcDataAdapter(oQRY, getConnectionString())
oDataAdapter.Fill(oDataSet)
Return oDataSet
End Function
Dim oQRY As String
Protected Sub LoginUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginUser.Click
'check if the login details exist
Dim user As String = UserName.Text
Dim pass As String = FormsAuthentication.HashPasswordForStoringInConfigFile(Password.Text, "MD5")
'thomas you need to change this to reflect your database
oQRY = "SELECT users.username, users.password, roles.role " + _
"FROM ((users INNER JOIN userRoles ON users.userID = userRoles.userID) INNER JOIN roles ON userRoles.roleID = roles.roleID) " + _
"WHERE users.username='" + user + "' AND users.password='" + pass + "' AND roles.role='bloguser'"
Dim oDataSet As DataSet = CreateDataSource(oQRY)
If oDataSet.Tables(0).Rows.Count > 0 Then
Dim ticket As FormsAuthenticationTicket = _
New FormsAuthenticationTicket(1, user, DateTime.Now, DateTime.Now.AddMinutes(60), True, "bloguser", FormsAuthentication.FormsCookiePath)
' Ticket version
' Username to be associated with this ticket
' Date/time issued
' Date/time to expire
' "true" for a persistent user cookie (could be a checkbox on form)
' User-data (the roles from this user record in our database)
' Path cookie is valid for
' Hash the cookie for transport over the wire
Dim hash As String = FormsAuthentication.Encrypt(ticket)
Dim cookie As HttpCookie = _
New HttpCookie(FormsAuthentication.FormsCookieName, hash)
' Name of auth cookie (it's the name specified in web.config)
' Hashed ticket
'Add the cookie to the list for outbound response
Response.Cookies.Add(cookie)
'Redirect to place they want to go to
Dim returnUrl As String = Request.QueryString("ReturnUrl")
If returnUrl Is Nothing Then returnUrl = "home.aspx"
' Don't call the FormsAuthentication.RedirectFromLoginPage since it could
' replace the authentication ticket we just added...
Response.Redirect(returnUrl)
Else
InvalidLogin.Text = "ERROR: Invalid Username, Password combination."
InvalidLogin.Visible = True
End If
End Sub
End Class
Could anyone help me with this problem?! As Im not sure whats wrong and how to fix the problem!
Thanks
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
This is the code where the exception is thrown:-
Imports System.Data.Odbc
Imports System.Configuration
Imports System.Web.Security
Public Class Login
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Protected UserName As System.Web.UI.WebControls.TextBox
Protected Password As System.Web.UI.WebControls.TextBox
Protected Persistent As System.Web.UI.WebControls.CheckBox
Protected WithEvents LoginUser As System.Web.UI.WebControls.Button
Protected InvalidLogin As System.Web.UI.WebControls.Label
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
' if the querystring contains a "Action=logout" param, logout and delete the cookie
If Request.Params("Action") = "logout" Then
FormsAuthentication.SignOut()
End If
End If
End Sub
' Protected Sub LoginUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginUser.Click
' check username and password
' If FormsAuthentication.Authenticate(UserName.Text, Password.Text) Then
' if ok, save the cookie
' FormsAuthentication.SetAuthCookie(UserName.Text, Persistent.Checked)
' redirect to Default.aspx
' Response.Redirect("Default.aspx", True)
'Else
' if wrong credentials, show the error message
' InvalidLogin.Visible = True
' End If
'End Sub
Protected Shared Function getConnectionString() As String
'Pass the connectionstring in the appsettings of the web.config file
Return ConfigurationManager.AppSettings("Blog_ConnString")
End Function
Function CreateDataSource(ByVal sql As String) As DataSet
Dim oQRY As String = sql
Dim oDataAdapter As OdbcDataAdapter
Dim oDataSet As DataSet = New DataSet()
oDataAdapter = New OdbcDataAdapter(oQRY, getConnectionString())
oDataAdapter.Fill(oDataSet)
Return oDataSet
End Function
Dim oQRY As String
Protected Sub LoginUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginUser.Click
'check if the login details exist
Dim user As String = UserName.Text
Dim pass As String = FormsAuthentication.HashPasswordForStoringInConfigFile(Password.Text, "MD5")
'thomas you need to change this to reflect your database
oQRY = "SELECT users.username, users.password, roles.role " + _
"FROM ((users INNER JOIN userRoles ON users.userID = userRoles.userID) INNER JOIN roles ON userRoles.roleID = roles.roleID) " + _
"WHERE users.username='" + user + "' AND users.password='" + pass + "' AND roles.role='bloguser'"
Dim oDataSet As DataSet = CreateDataSource(oQRY)
If oDataSet.Tables(0).Rows.Count > 0 Then
Dim ticket As FormsAuthenticationTicket = _
New FormsAuthenticationTicket(1, user, DateTime.Now, DateTime.Now.AddMinutes(60), True, "bloguser", FormsAuthentication.FormsCookiePath)
' Ticket version
' Username to be associated with this ticket
' Date/time issued
' Date/time to expire
' "true" for a persistent user cookie (could be a checkbox on form)
' User-data (the roles from this user record in our database)
' Path cookie is valid for
' Hash the cookie for transport over the wire
Dim hash As String = FormsAuthentication.Encrypt(ticket)
Dim cookie As HttpCookie = _
New HttpCookie(FormsAuthentication.FormsCookieName, hash)
' Name of auth cookie (it's the name specified in web.config)
' Hashed ticket
'Add the cookie to the list for outbound response
Response.Cookies.Add(cookie)
'Redirect to place they want to go to
Dim returnUrl As String = Request.QueryString("ReturnUrl")
If returnUrl Is Nothing Then returnUrl = "home.aspx"
' Don't call the FormsAuthentication.RedirectFromLoginPage since it could
' replace the authentication ticket we just added...
Response.Redirect(returnUrl)
Else
InvalidLogin.Text = "ERROR: Invalid Username, Password combination."
InvalidLogin.Visible = True
End If
End Sub
End Class
Could anyone help me with this problem?! As Im not sure whats wrong and how to fix the problem!
Thanks