Access database path

J

Jason

I would like my database path in the connecton string to be relative to the
document calling the path so that I can deploy the application in any folder
and it will still work without changing the path to the database.

For example.

I have an access database and asp.net application on my development machine
located in c:\development\project but when I deploy the application it will
be located in c:\inetpub\wwwroot\project. If I try to use a relative path
to the database for example Data source="accessdb.mdb" It fails, it seems
like it is looking in system32 or something like that. But I don't want to
put the full path because then I have to change it everytime I deploy the
application. I relize I could use a global variable or something like that
for the connection string, but I'd still have to change the path in one
place everytime I deployed it. I have got to be missing something simple
here.

Thanks in advance,

Jason
 
W

William Ryan eMVP

Jason
Jason said:
I would like my database path in the connecton string to be relative to the
document calling the path so that I can deploy the application in any folder
and it will still work without changing the path to the database.

For example.

I have an access database and asp.net application on my development machine
located in c:\development\project but when I deploy the application it will
be located in c:\inetpub\wwwroot\project. If I try to use a relative path
to the database for example Data source="accessdb.mdb" It fails, it seems
like it is looking in system32 or something like that. But I don't want to
put the full path because then I have to change it everytime I deploy the
application. I relize I could use a global variable or something like that
for the connection string, but I'd still have to change the path in one
place everytime I deployed it. I have got to be missing something simple
here.

Thanks in advance,

Jason

Would something like this work for you...you'd just need to keep the access
db in the same directory as the assembly
Path.GetDirectoryName(Application.ExecutablePath.ToString) & "accessdb.mdb")
 
P

Paul Clement

¤ I would like my database path in the connecton string to be relative to the
¤ document calling the path so that I can deploy the application in any folder
¤ and it will still work without changing the path to the database.
¤
¤ For example.
¤
¤ I have an access database and asp.net application on my development machine
¤ located in c:\development\project but when I deploy the application it will
¤ be located in c:\inetpub\wwwroot\project. If I try to use a relative path
¤ to the database for example Data source="accessdb.mdb" It fails, it seems
¤ like it is looking in system32 or something like that. But I don't want to
¤ put the full path because then I have to change it everytime I deploy the
¤ application. I relize I could use a global variable or something like that
¤ for the connection string, but I'd still have to change the path in one
¤ place everytime I deployed it. I have got to be missing something simple
¤ here.

Try using AppDomain.CurrentDomain.BaseDirectory


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

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