Hi, everyone this is my first post here and let me tell you my problem

I have a C# application, i have SQLServer 2005 installed on my computer
my database is there and the program works fine

the problem I'm facing is that i need to make an installer for this application to install it on a client that doesnt have sql server on it

i can make the installer just fine

the problem is on my code, to test my code on my computer i have to put the sql string like this

String rutaconexion = "Data Source=.\\SQLEXPRESS; initial catalog = labtol ;Integrated Security=True";

and this works fine in my test computer
after i make the installer the problem i face is that how to attach the database, where the database needs to be placed, or what is the code to do so
I was using this to attach the database

String rutaconexion = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Labtol.mdf; initial catalog = labtol ;Integrated Security=True";

Labtol is the name of my database

Any help would be appreciated. Thanks

Recommended Answers

All 4 Replies

Did you attach the db into your project?
You attach the db to your project when selecting new databse (Tab- Data-> Add new DataSource) On the 2nd page you got a question: Would you like to copy the file to your prouject and modify the connection? You have to choose Yes.
And as you have figured it out, the connection string needs to have a |DataDirectory| path, instead of full path.

And btw, better get rid of double sleshes from connection string, it has to look like that:

connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectoryˇ|\test01DB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

Did you attach the db into your project?
You attach the db to your project when selecting new databse (Tab- Data-> Add new DataSource) On the 2nd page you got a question: Would you like to copy the file to your prouject and modify the connection? You have to choose Yes.
And as you have figured it out, the connection string needs to have a |DataDirectory| path, instead of full path.

And btw, better get rid of double sleshes from connection string, it has to look like that:

connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\test01DB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

I attached the database to the project, now my questions is if I need to change something in the connectionString??

No. You only need to change the full path with the relative path (instead of C:\Folder\myDb.mdf you do : |DataDirectory|\myDb.mdf
thats all!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.