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

adding a database to a setup project. 2

Status
Not open for further replies.

pinkwho

Programmer
May 7, 2002
10
0
0
US
I have a project in VB.Net (VS 2003) that I have added a setup project to. Everything works great on the development PC. I am putting the database in my project as well as in the application folder in the set up project. When I try to run the application (setup runs flawlessly both on the development and test machine) on the test machine however it is still looking for the database in the original path where the database was stored on the development machine (and of course this directory doesn't exist, infact the PROFILE (WINXP) doesn't even exist). If I manually create the path and put the mdb in the correct folder, the program runs flawlessly. My question is, how can I tell my program to look for the DB in the "c:\program files\some company\some program" directory for the mdb?? Any help is appreciated. Thanks - btw this community rocks.
 
You have to modify the connection string. It should be something like : (dynamic)

"...Data Source=" & application.startupPath & "\!@#.mdb"

Installing it in "c:\program files\some company\some program", the exe (main program) will be on this root. Assuming that the database is in /afolder/

"...Data Source=" & application.startupPath & "\afolder\!@#.mdb"

Hope this helps you!

** Also you could use a openfiledialog to browse for the database and strore the path in a txt file.
 
You can add an app.config file with the path in it and have your app check that.

Sort of like the old INI file...

< M!ke >
 
Installing it in "c:\program files\some company\some program", the exe (main program) will be on this root. Assuming that the database is in /afolder/
Actually, the more correct place for it is in the ApplicationData special folder, which if it's needed for all users of the system, is usually:
[tt]C:\Documents and Settings\All Users\Application Data\<companyName>\<productName>[/tt]

or if it's per-user:
[tt]C:\Documents and Settings\<username>\Application Data\<companyName>\<productName>[/tt]

You can easily find these folders via the SpecialFolder enumeration. [tt]SpecialFolder.CommonApplicationData[/tt] and [tt]SpecialFolder.ApplicationData[/tt]. You would then append your company name and product name to these values using the [tt]Path.Combine[/tt] method to build up a correct directory path.

If you use the enumeration, it'll work correctly even if the user has a roaming profile, or is running on a Citrix box.

Chip H.

____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
In your application you could also check to see if the folder you want to put your db exists. If it dowsn't then have the application create it.

On the other hand, does everry user need access to this db? If so, why not put it on a network resource and add that path to your connection string? That way you don't have to worry about folders existing on everyone's pc and make maint. that much easier.
 
I thank all of you for your replies, in order from last to first:

PR: The db needs to be local per machine, it's an imported excel doc with vital info.

CHIP: I get what you are saying and but I would like to keep it encapsulated.

LNB: Understood and noted although I'd like something a little ... cleaner if you know what i mean.

TipG: I really like where you are headed.

That said, perhaps I didn't give enough info. I would like to do Tip's suggestion, however perhaps I didn't give enough info; I am using an OleDbDataAdapter, an OleDbConnection, and a dataset generated from that. I am not writing an SQL statement. that said would it be possible to put the path in using these controls, or will I have to start using an SQL statement? I have everything finished and I am venturing into new territory, I don't have problems with SQL or coding it... it's coding it in .NET that I have VERY[/] little experience in.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top