Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello,

How can I pass connection string to the program while it's installing?
Posted
Comments
BotCar 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

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="">
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

C#
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();


C#
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.
 
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