[英]do i need to edit connection string in my c# application when i install it in a client pc, if yes how can i do it?
I have created a software in C#, using SQL Databases (SQL server). 我已经使用SQL数据库(SQL Server)在C#中创建了一个软件。 and I'm planning to deploy it and use SQL Server Compact instead of installing SQL server in the client PC . 我计划部署它并使用SQL Server Compact,而不是在客户端PC中安装SQL Server。
and it seems that i need to replace the connection string in my code so it contain the name of the client PC . 似乎我需要替换代码中的连接字符串,以使其包含客户端PC的名称。 (I'm not sure 100% ). (我不确定100%)。
so if i have to change it how can i do it , and is there is any way to generate the connection string and change it in my code automatically when i install my app or after i install it in other PC's . 因此,如果我必须更改它,我该怎么做,是否有任何方法可以生成连接字符串,并在我安装应用程序时或在其他PC上安装它后在代码中自动对其进行更改。
thank you . 谢谢 。
Add the connection string to the App.Config and get the code to get the connection string from the App.Config. 将连接字符串添加到App.Config,并获取代码以从App.Config获取连接字符串。 That way, when releasing to any environment, just change the value in the one place. 这样,当发布到任何环境时,只需在一个位置更改值即可。
You should code the connection string so that it can be dynamic, as opposed to making it hard-coded in the config. 您应该对连接字符串进行编码,以便它可以是动态的,而不是在配置中对其进行硬编码。 Passing a connection string in code before your db call is trivial. 在进行数据库调用之前,在代码中传递连接字符串很简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.