Connecting to an Access database in Classic ASP us

2019-08-08 16:14发布

问题:

I am new to classic ASP. I would rather ask question than do hour of research to solve my problem.

I am accessing access database and getting the following error.

Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified    
/default1.asp, line 30

The culprit line is this

Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = Server.MapPath("c:\database\MyDatabase.mdb") 
  1. Well, I do not have Access installed but I copied the .mdb file to the specified folder, will it work that way? I am familiar with SQL Server, and that has to run in order to retrieve data from it.

  2. It uses ADODB but I can't file the DLL. Can someone specify the DLL for me. What I have to do to get it working. Just registering it will work using regsvr32 my.dll?

  3. I could not find a connection string (I usually use a connection string to connect to my SQL Server). Do I need one for Access database in this case?

Please help

回答1:

It's been a few years for me, so this answer might be a little out of date. Also, since the Access db ends in .mdb, I'm assuming that it's a pre-2007 database.

Yes, just the file should work. Access does not need to run, it just needs to read the file. However, you may need certain components installed to talk to the Access database (used to be MDAC - http://www.microsoft.com/download/en/details.aspx?id=1953, not 100% certain if it still is). MDAC contains the JET engine, which classic ASP uses to talk to Access files.

As for the connection string, this web site that provides some examples of access connection strings: http://connectionstrings.com/access

edit - adding more info

Just in case I'm not following the comments correctly, here's an example of how to connect to the Access database through Classic ASP:

Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = "c:\database\MyDatabase.mdb" ''# Server.MapPath is not needed, since we are providing the whole path already
MyConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & MdbFilePath

When running the code above, do you receive the error still? Also, what's the set up you're running (IIS7, IIS6, 32bit, 64bit)?