My First Build Release

macleodjb

Member
Joined
Jan 1, 2011
Messages
8
Programming Experience
Beginner
Hi Guys,

I'm getting ready to release my first build of an application that i have designed and have a question in regards to the database that i have integrated.

In my application i have included a database in which the connection string is hard coded for the path to the database such as X:/Vbnet Projects/my project/database.mdb

My question is upon deployment it will most likely be installed in C:/Program Files/MyApp
is it proper for me to just change the connection string to the manual installation path or is there a way to automate the path. I know upon installation the user has the ability to select their own installation path, how do i account for that?

Thanks in advance.
 
The way local data files should work is like so:

1. You add the data file to your project.
2. You set the Copy To Output Folder property to Copy If Newer.
3. You use |DataDirectory| as the folder path for the data file in your connection string.

Now, the application will always connect to the data file in the same folder as the EXE, whether that be bin\Debug or any folder on any machine after deployment. You simply deploy the contents of bin\Release, which will include the EXE and the data file, and it will just work. No need to change the connection string at all.
 
Thanks for the help. I'm not sure what my true problems are at this point.

My Connection string looks like this right now.

VB.NET:
ConnString = "Data Source=.\SQLEXPRESS;AttachDbFilename='" & Application.StartupPath & "\mydatabase.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True"

And this seems to work fine in windows 7, but when i try to install this on windows xp the application doesn't even run. It dies on initialization and wants me to report the error to microsoft. I am assuming this is a .net error but haven't a clue on how to fix it. This app is created in .net 4. And the XP machine has .net 4 framework installed.

I'm not sure where to set #2 in your post.

Thanks for the help.
 
You set properties in the Properties window.

As I said, use |DataDirectory|:
VB.NET:
ConnString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory\mydatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
 
Back
Top