Sam
Sam

Reputation: 183

Connect to MS Access database from classic ASP

I am trying to connect a MS Access database from classic ASP script.

I am using 64bit Windows 7 OS running IIS7

I have following piece of code:

Dim Connection
Set Connection = Server.CreateObject("ADODB.Connection")
Response.Write("object created...")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("D://Somnath//ExtraLogistics//Source//ZipDB.mdb") & ";" 
Response.Write("connected...")

but I am getting this error The website cannot display the page in browser while running application on IIS.

Please help me to connect to the Access database from my IIS.

Upvotes: 0

Views: 4673

Answers (4)

Guido Gautier
Guido Gautier

Reputation: 1233

Please note that you want to store your database in a parent directory relative to the location where you execute the asp files. If you don't the database is available through a url in the browser.

Also note that to make this work, 'Allow Parent Paths' must be enabled in IIS.

Upvotes: 0

Drgnkght
Drgnkght

Reputation: 121

Server.MapPath converts a URL path to the physical path on the server so Server.MapPath("D://Somnath//ExtraLogistics//Source//ZipDB.mdb") is almost certainly wrong.

If the mdb file is located at http://yourhost/Somnath/ExtraLogistics/Source/ZibDB.mdb then you would use Server.MapPath("/Somnath/ExtraLogistics/Source/ZibDB.mdb") and Server.MapPath would give you the location of the mdb file in the server's filesystem.

If the file is located at D:\Somnath\ExtraLogistics\Source\ZipDB.mdb then just use that filepath and remove Server.MapPath completely.

Like so: conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Somnath\ExtraLogistics\Source\ZipDB.mdb;"

Upvotes: 0

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114347

Use a "file dsn":

conn.open "driver={Microsoft Access Driver (*.mdb)};dbq=c:\filepath\yourdb.mdb;"

Upvotes: 1

Your MapPath does not look correct.

Have a look at this ASP reference.

EDIT:

Server.MapPath points to the Physical location of a virtual reference:

For Example:
'Physical path of the root directory
Response.Write Server.MapPath("/")

'Physical path of DataDirectory
Response.Write Server.MapPath("/DataDirectory/")

Place the ZipDB.mdb in the root of your website and change the Server.MapPath("/")

Upvotes: 1

Related Questions