Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hello,
 
How can I pass connection string to the program while it's installing?
Posted 23-Nov-12 1:41am
Comments
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
good
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
like...
<?xml version="1.0"?>
<configuration>
	<appSettings>
		<add key="Server" value=""/>
		<add key="Database" value=""/>
		<add key="ConnectionTimeout" value=""/>
		<add key="UserID" value=""/>
		<add key="Password" value=""/>
	</appSettings>
</configuration>
add refrence of system.configuration dll.
 
To retrieve data of this config file use
ConfigurationManager.AppSettings[key]
 
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 280
1 Sergey Alexandrovich Kryukov 279
2 CPallini 205
3 Maciej Los 162
4 Afzaal Ahmad Zeeshan 160
0 OriginalGriff 5,635
1 DamithSL 4,496
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2014
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