Relative path

  • Thread starter Thread starter Hai Nguyen
  • Start date Start date
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
 
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.
 
Back
Top