Click here to Skip to main content
13,195,163 members (66,727 online)
Rate this:
Please Sign up or sign in to vote.
See more:

How can I pass connection string to the program while it's installing?
Posted 23-Nov-12 0:41am
TheOtherCPian 23-Nov-12 8:35am
This question looks incomplete. Maybe you should try using the "Improve Question" widget to make your question more understandable.

1 solution

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

Solution 2

I think its bad idea to create a connection string at installation because if the string is not working then what?

its better if you use config file and create connection string from that config file.

for doing that you need to add a config file in your project. by default it is app.config.

now add <appsetting />tag inside the config file and add<key name="" and="" value="">
<?xml version="1.0"?>
		<add key="Server" value=""/>
		<add key="Database" value=""/>
		<add key="ConnectionTimeout" value=""/>
		<add key="UserID" value=""/>
		<add key="Password" value=""/>

add refrence of system.configuration dll.

To retrieve data of this config file use

now make connection string as

string ServerName = ConfigurationManager.AppSettings["Server"].ToString();
string Database =  ConfigurationManager.AppSettings["Database"].ToString();
string ConnectionTimeout =  ConfigurationManager.AppSettings["ConnectionTimeout"].ToString();
string UserID =  ConfigurationManager.AppSettings["UserID"].ToString();
string Password =  ConfigurationManager.Apps["Password"].ToString();

ConnectionString = "Data Source=" + ServerName + ";" +
                    "Initial Catalog=" + DataBaseName + ";" +
                    "Persist Security Info=True;" +
                    "User ID=" + UserID + ";" +
                    "Password=" + Password + ";" +
                    "Pooling=true;" +
                    "Connection Timeout=" + ConnectionTimeout;

now i think you got idea about i mean to say.
Whenever you wanted to change the connection string setting open that config file and change the value accordingly and the setting will applied.

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

Advertise | Privacy |
Web01 | 2.8.171019.1 | Last Updated 28 Nov 2012
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