Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DSN-less Connection Questions 3

Status
Not open for further replies.

inf33323

Technical User
Apr 24, 2001
26
DE
Hi all,

I would like to connect to a Access2000 database using a DSN-less connection and I don't understand why I keep getting some errors.

Everything works fine if I provide the absolute path to my database like in the snippet:

Set myConn = Server.CreateObject("ADODB.Connection")
myConn.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= C:\Inetpub\review\Source\Review.mdb"

If I use the Server.MapPath method like in the following

Set myConn = Server.CreateObject("ADODB.Connection")
Set myPath = Server.MapPath("/review") & "\Source\Review.mdb"

myConn.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " & myPath

...I get this error:

Microsoft VBScript runtime (0x800A01A8)
Object required: '[string: "C:\Inetpub\review\So"]'
/review/MainProjektNr.asp, line 13

This was the first question. The second one is shorter: does the database have to be located on the server machine. I tried connecting to a database on a remote machine (in the same NT network) and it didn't work at all.

Thanks a lot for any input.

inf33323
 
I think Server.MapPath() returns a string, not an object.
I think Set is used to assign an object to a variable (or variant).

Could this be the source of the Object Required error?
 
I thought that the Data Source must be a string. If I provide the Data Source name manually I enter the location of my database and this is a string!!!
 
When I get errors with Server.MapPath I generally do a Response.Write on the string returned by the MapPath to ensure it is pointing in the right direction. The reason why this gets tricky is that the Server.MapPath maps the path to the directory in which the actual ASP page resides. If your ASP page is in the C:\Inetpub directory, then the code should look like this:

Set myConn = Server.CreateObject("ADODB.Connection")
myConn.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("review\Source\Review.mdb")

Hope this helps!

sjuarez1979
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top