C#应用程序安装和 [英] C# application installation and

查看:45
本文介绍了C#应用程序安装和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

Hello,

How can I pass connection string to the program while it''s installing?

推荐答案

我认为在安装时创建连接字符串是一个坏主意,因为如果该字符串是那不行怎么办?

如果使用配置文件并从该配置文件创建连接字符串,则更好.

为此,您需要在项目中添加配置文件.默认情况下为app.config.

现在在配置文件中添加< appsetting>标记,并添加< key name ="和=" value =">
喜欢...
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>


添加system.configuration dll的引用.

要检索此配置文件的数据,请使用


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.


这篇关于C#应用程序安装和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆