Click here to Skip to main content
12,952,443 members (40,055 online)
Rate this:
Please Sign up or sign in to 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

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

and in App.config

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

Plz give solution.
Posted 17-Sep-11 8:29am
Updated 17-Sep-11 8:34am
digimanus 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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 19 Sep 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100