PDA

View Full Version : ASP - unable to locate database



fouraces
05 Feb 2009, 05:42 PM
Hi there,

Upon following an example from an ASP book, i have stumbled across the MS Access data source connection error message:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

/20527796/assignment2/verify.asp, line 115

I have been told to specify the database name as my user ID (20527796) which i have also specified in the code:

(global.asa)
Code:


<SCRIPT LANGUAGE=vbscript RUNAT=Server>

Sub Application_OnStart()
Application("SiteURL") = "http://intasp.bcuc.ac.uk/20527796/assignment2/"
Application("DBSource") = "20527796"
Application("LogonErrFile") = "LogonErr.asp"
Application("AccessErrFile") = "AccessErr.asp"
End Sub

Sub Session_OnStart()
Session("IsGoodUser") = False
Session("FirstName") = ""
Session("LastName") = ""
Session("CurrentURL") = ""
Session("UserID") = ""
End Sub

Sub Application_OnEnd()

End Sub
Sub Session_OnEnd()
Session.Abandon
End Sub
</SCRIPT>



default.asp contains the log in dialog. verify.asp is fired up once the visitor clicks 'logon' to verify that they are registered within the database and that the user name and password matches. verify.asp checks the database for these items, but its seems as though it cannot locate the database:

(verify.asp)
Code:


<%

Sub GetNames(LoginID, FirstName, LastName)

Dim cn 'Connection var
Dim rs 'Recordset var
Dim strSQL 'SQL Statement var
Dim strCn 'Connection String var


'Create a Connection Object
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
'Make the SQL statement that returns
'the user with password, should one exist
strSQL = "SELECT * FROM tblTeachers WHERE TeacherID = '"
strSQL = strSQL & LoginID & "'"


'Set error trappong
'On Error Resume Next
'Open the Connection
cn.ConnectionString = "DSN=" & Application("DBSource")
cn.Open
If Err Then Exit Sub

'Get the user from the DB
rs.Open strSQL, cn
If Err Then Exit Sub

'This checks to make sure if no
'recordset was returned
MyErr = rs("FirstName")
If err then
Exit Sub
End if
'Wire up the return fields
FirstName = rs("FirstName")
LastName = rs("LastName")

rs.Close
cn.Close
End Sub


Function Login(LoginID, Password)


Dim cn 'Connection var
Dim rs 'Recordset var
Dim strSQL 'SQL Statement var
Dim strCn 'Connection String var



'Create a Connection Object
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
'Make the SQL statement that returns
'the user with password, should one exist
strSQL = "SELECT * FROM tblLogin WHERE LoginName = '"
strSQL = strSQL & LoginID & "'"


'Set error trappong
On Error Resume Next
'Open the Connection
cn.ConnectionString = "DSN=" & Application("DBSource")
cn.Open
If Err Then Exit Function

'Get the user from the DB
rs.Open strSQL, cn
If Err Then Exit Function

'This checks to make sure if no
'recordset was returned
MyErr = rs("PWD")
If err then
Exit Function
End if

'If the passwords match up, return TRUE
If rs("PWD") = Password Then
Login = True
Else
Login = False
End If
'Leave town
rs.Close
cn.Close
End Function

'=========Entry Point============
If Login(Request.Form("LoginID"), Request.Form("PWD")) Then
'Set a session level var for the UserID
Session("UserID") = Request.Form("LoginID")

Dim FirstName
Dim LastName


'Get the teachers First Name and Last Name
GetNames Session("UserID"), FirstName, LastName

'Set a session level var for the FirstName and LastName
If FirstName <> "" Then Session("FirstName") = FirstName
If LastName <> "" Then Session("LastName") = LastName
'If the login data is good, redirect the visitor
'to the site's content directory
Session("IsGoodUser") = True
Response.Redirect "main.asp"
Else
'Report a logon error.
Response.Redirect Application("LogonErrFile")
End If
%>


It may be that the connection string is of the wrong type for the desired connection. If this is the problem, is there an alternative way to connect to the database.

p.s. I have granted full access permissions over the database to eliminate permission problems.

Any help towards this quandrary will be appreciated.

Many thanks,

stroodle!