Jump to content

Connecting to database (continued from category general)


Anders Moen

Recommended Posts

I just copied my last post from the category general:

Set oConn = Server.CreateObject("ADODB.Connection")sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _			  "Data Source=" & Server.MapPath("\UserName\db\dbname.mdb") & ";" & _			  "Persist Security Info=False"oConn.Open(sConnection)'...oConn.Close

You replace Username with your actual user name. Do you have your database in the db folder of your account? It will not work anywhere else.Did you upload an existing database or use their database manager to create a new one?

I made one online at them. Look at my code now:
<%Set oConn = Server.CreateObject("ADODB.Connection")sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _			  "Data Source=" & Server.MapPath("c:\sites\content\a\n\d\andersmoen\db\anders.mdb") & ";" & _ // This is my path to the database.			  "Persist Security Info=False"oConn.Open(sConnection)'...oConn.Close%>

Here's the error message I get:

Server.MapPath() error 'ASP 0172 : 80004005' Invalid Path /a/n/d/andersmoen/index.asp, line 11 The Path parameter for the MapPath method must be a virtual path. A physical path was used.
And it says my path is at my control panel: c:\sites\content\a\n\d\andersmoenand with database it'll be c:\sites\content\a\n\d\andersmoen\db\news.mdbI seriously start hating Microsoft for making it so difficult now:P
Link to comment
Share on other sites

Microsoft VBScript compilation error '800a03ea' Syntax error /a/n/d/andersmoen/index.asp, line 14 "Data Source=" & Server.MapPath("\andersmoen\db\anders.mdb") & ";" &--------------------------------------------------------------------^
Here's my site if you wanna see yourself: http://andersmoen.brinkster.net/
Link to comment
Share on other sites

it is not MS that makes it hard. I found that Brinkster makes it harder than it should be and plus PHP makes it very easy because they wrote the mysql library around database interaction. There isn't a built in db library for ASP.

Link to comment
Share on other sites

I don't understand a thing now...Look:I tried with absolute root path: (c:\sites\content\a\n\d\andersmoen\db\anders.mdb), and I've tried with only \andersmoen\db\anders.mdb and andersmoen\db\anders.mbd but I get error message every time.

"Data Source=" & Server.MapPath("c:\sites\content\a\n\d\andersmoen\db\anders.mdb") & ";" & _gives this error message:Server.MapPath() error 'ASP 0172 : 80004005' Invalid Path /a/n/d/andersmoen/index.asp, line 12 The Path parameter for the MapPath method must be a virtual path. A physical path was used.
"Data Source=" & Server.MapPath("andersmoen\db\anders.mdb") & ";" & _gives this error message:Microsoft JET Database Engine error '80004005' 'C:\Sites\content\a\n\d\andersmoen\andersmoen\db\anders.mdb' 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. /a/n/d/andersmoen/index.asp, line 17
Link to comment
Share on other sites

If you read the server,mappath in w3schools, then there is an explanation about using a "/" and not using it in Server.MapPath("\andersmoen\db\anders.mdb") When I tested it in localhost, If you start with a "/" then path is c:\inetpub\wwwroot and concatenates the path we mention insideabove.Incase if your page is in folder in wwwroot and if given without "/" it gives path path including that folder i.e the path of the page.c:\inetpub\wwwroot\subfolder\If without "/" it returns a path relative to the directory of the .asp file being processedso make sure you print the path and see if its correct.

Link to comment
Share on other sites

In the error, asp page is looking for the database file in this location, this guess is not the correct path.'C:\Sites\content\a\n\d\andersmoen\andersmoen\db\anders.mdb'If you currect .asp page is inside "andersmoen" folder then try,Server.MapPath("db\anders.mdb")

Link to comment
Share on other sites

Okay, what's wrong with this code then?

<%Set oConn = Server.CreateObject("ADODB.Connection")sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _			  "Data Source=" & Server.MapPath("db\news.mdb") & ";" & _			  "Persist Security Info=False"oConn.Open(sConnection)'...oConn.Close%>

I just get this error message:Microsoft JET Database Engine error '80004005' Unrecognized database format 'C:\Sites\content\a\n\d\andersmoen\db\news.mdb'. /a/n/d/andersmoen/index.asp, line 18

Link to comment
Share on other sites

nothing appears wrong. I found back int he day when I used Brinkster that it would sometimes take a while before the asystem recognized a new database I created. After a while it would just start to work.

Link to comment
Share on other sites

Okay, I just tried the code again

<%Set oConn = Server.CreateObject("ADODB.Connection")sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _			  "Data Source=" & Server.MapPath("db\anders.mdb") & ";" & _			  "Persist Security Info=False"oConn.Open(sConnection)'...oConn.Close%>

but now I just get this message:

Microsoft JET Database Engine error '80004005' Unrecognized database format 'C:\Sites\content\a\n\d\andersmoen\db\anders.mdb'. /a/n/d/andersmoen/index.asp, line 17
But at least it's almost good then, or? Anybody got any ideas for why it's like this then? =/
Link to comment
Share on other sites

I've already done that, and they just sent me a link to the site with different types of connections, but I didn't get anyone of them to work =/But I will try again later today/tomorrow and then I'll tell you if it works this time.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...