p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   Problems opening MS Access database (http://p2p.wrox.com/showthread.php?t=43516)

JayM June 5th, 2006 01:52 PM

Problems opening MS Access database
 
I'm using the following code in an ASP page (obviously there's more but this is the minimal testing code):

<%
'create ADO objects
Set cn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")

'Open connection.
strDBlocation = Request.ServerVariables("APPL_PHYSICAL_PATH") & "database\NDTdatabase.mdb"
strConn = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & strDBlocation & ";"
Response.write strConn
cn.Open strConn

'rs.Close
'cn.Close

The web server is on the same computer (Windows XP with IIS 5.0) that I'm using for development. Originally, I had the web application and database in an IIS virtual directory.

The error message I get from the cn.open strConn statement is:

Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

Commenting out the cn.Open statement, the Response.write displays:

Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:\inetpub\wwwroot\database\NDTdatabase.mdb;

I moved the application directly under wwwroot and moved the database to the same directory as the asp file to see if that would solve the problem. I commented out the strDBlocation, strConn, and previous cn.open statements and added the following:

cn.Open Driver={Microsoft Access Driver (*.mdb)}; DBQ=NDTdatabase.mdb;

I got the following error message:
Microsoft VBScript compilation (0x800A0408)
Invalid character
/Classes/test.asp, line 109, column 15
cn.Open Driver={Microsoft Access Driver (*.mdb)}; DBQ=NDTdatabase.mdb;
--------------^

I finally realized that the complaint was for the character after the =, so I put the Driver argument in quotes:

cn.Open Driver="{Microsoft Access Driver (*.mdb)}; DBQ=NDTdatabase.mdb;"

Now, I've got the error message:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
/ndt/classes/test.asp, line 109

Eventually, I would like to have the database in a separate directory because it is accessed by several asp programs in several different directories.

I'm going nuts. Does anyone have any ideas?

Jay

gbianchi June 5th, 2006 01:59 PM

hi there.. try this..

build an udl file and construct the connection string in there... to connect to an access database use jet oledb 4.0 (it will connect to any version of an access database)...

then copy the connection string to your app. that will sure solve your problem with the connection...

HTH

Gonzalo


All times are GMT -4. The time now is 08:17 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.