Click here to Skip to main content
11,718,016 members (85,994 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0

How can I pass connection string to the program while it's installing?
Posted 23-Nov-12 0:41am
TheOtherCPian at 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 tag inside the config file and add
<?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
0 OriginalGriff 215
1 F-ES Sitecore 210
2 Maciej Los 140
3 Jochen Arndt 120
4 Andy Lanng 115
0 Sergey Alexandrovich Kryukov 1,649
1 OriginalGriff 535
2 Maciej Los 529
3 Richard MacCutchan 440
4 CHill60 415

Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2015
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