Click here to Skip to main content
15,891,868 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to make setup of my windows application I am using sqlserver2008 as database server.
I have created Library named DBConnection for connection with database and using connection string from App.config file.
so how can put database in setup project to attach to server of client where this project is installed.

My ConnectionString is:

in cs file

C#
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[0].ConnectionString.ToString());

and in App.config

C#
<add name="Conn" connectionstring="Data Source=GANGARAM-PC\SQLEXPRESS;Initial Catalog=Ganga;Integrated Security=True" providername="System.Data.SqlClient" />



Plz give solution.
Posted
Updated 17-Sep-11 8:34am
v2
Comments
Herman<T>.Instance 17-Sep-11 14:36pm    
Just a TIP: where you state [0] for the connectionnumber you can better name it by using ["Conn"]. If someone install mysql server on the same machine you project start looking at mysqlserver with sqlserver instances. That definately will go wrong. By using the name you prevent this problem

1 solution

do a bit of searching and you will find solutions - such as here

What I did in my last project was to leave the connections string with a non valid value in the config, and my application checked it at start up and invoked a connections string editing form if it was invalid.

This has the advantage that, should the client need to change the location of their database, the application has the functionality available to change the connection string.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900