简体   繁体   English

当我在客户端PC中安装连接字符串时,我需要在c#应用程序中编辑连接字符串吗,如果可以,我该怎么做?

[英]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.

相关问题 如何找到通过C#应用程序自动执行SAP所需的连接字符串? - How do I find my Connection String required to automate SAP through a C# application? 如何编写外部连接字符串配置文件并使我的C#应用​​程序识别并读取它? - How do I write an external connection string config file and make my c# application recognize and read it? 如何创建非绝对连接字符串,以便我的小型数据库可以与已发布的C#应用​​程序一起使用? - How do I make a non absolute connection string so my small database works with my published C# application? 我如何做一个功能C#我可以从Android设备的PC和聊天客户端的服务器聊天接收消息? - How I do a function C# for i can receive messages from Server Chat in PC and Chat Client in Android device? 在Windows XP上如何在C#中使用语音识别? +我需要训练每台运行该应用程序的PC吗? - How can I use speech recognition with C# on Windows XP? + do I need to train every pc that runs the app? 如何在azure中为我的Web应用程序设置连接字符串? - how do i set the connection string for my web application in azure? 如何在没有管理员权限的情况下安装我的C#应用​​程序? - How Do I Make My C# Application Install Without Admin Rights? C#如何在Windows窗体应用程序中的字符串内部进行基本数学运算 - C# How do I do some basic math inside of a string in my Windows Form Application 在提交事务之前断点我的c#应用程序时,如何在SSMS中进行脏读? - How can I do a dirty read in SSMS when I breakpoint my c# application prior to commiting a Transaction? 如何在C#中更改sis中的连接属性? - How do I change connection properties in my ssis in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM