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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application.StartupPath not working

Status
Not open for further replies.

jmerencilla

Programmer
Jul 17, 2002
123
SG
question. i made a DLL that accesses an Access 2000 DB and test it using a Windows Application project. I'm sure that my DLL is working fine because I got my desired output while I was testing it. however when i tried accessing my DLL in a web application project, i got this error:


Could not find file 'C:\WINNT\Microsoft.NET\Framework\v1.0.3705\myDB.mdb'


and points to this line of code

Line 10: objConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Windows.Forms.Application.StartupPath & "\myDB.mdb;Persist Security Info=False")

Line 11:
Line 12: End Sub

what i'm trying to do here is access an Access DB located on the same path where my DLL resides. it works fine with windows app but not with a web app. what am i missing here?
thanks is advanced.

:)
 
The problem you're seeing there is this:

You've probably put that .mdb in the /bin folder, because that's where your dll "is". Actually, what happens during the jit compilation process when you first run a page is that dll is copied to a temp folder on that path that it shows you there.

The reason they do this is so you can use the xcopy method for deployment, and you aren't actually copying over the dll that the system is using (remember how bad it was to replace a .dll in com?).

My suggestion would be to make a db folder on your machine -- out of the reach of ftp, and put all your databases there. Nice and clean.

Actually, I would recommend not using Access for a web database. MSDE is free, you know.

hth :)
paul
penny1.gif
penny1.gif
 
yup. that'w what i did. i placed my db where my dll resides (..\bin directory). if ever i am to move my db in a separate folder, le't say at c:>myDB\, how would i be able to access my myDB.mdb file in that directory? as i told you before, Application.StartUpPath works fine with a Windows Application project. thanks :)
 
You would just set up your connection string as:

c:\myDB\myDB.mdb
penny1.gif
penny1.gif
 
is there a way to this this without resorting to hard coding? i mean, i can place my database anywhere i want and still the application works fine.
 
you can use server.mappath to make it find the absolute path based on a relative location to your app, but that's about it.

say you always wish to place it two levels above your app, then:

server.mappath(../../myDB.mdb")

will give you the absolute path to plug into your connection string.
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top