Relative path

H

Hai Nguyen

Hi All:

If I want to connect to an Access data base, the aspx page and the database
are located in the same folder, how would I refere to the database?

I got an error when refere to an Access database if the string connection
does not provide absolute path.
eg:
OleDbConnection myConnection = new OleDbConnection(
"PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=authors.mdb" );
then I got the following error:

Exception Details: System.Data.OleDb.OleDbException: Could not find file
'C:\WINNT\system32\authors.mdb'.

even my authors.mdb is not located at C:\WINNT\system32 folder.

TIA.

Hai
 
N

Nicholas Paldino [.NET/C# MVP]

Hai,

You can use the MapPath method on the Server property exposed by the
Page to get the physical path of a file based on the virtual path. So in
your case, you would pass it the name of page and then it will return the
full path. If you pass it just ".", it should return the directory, and
then you can use that to access your database.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top