如何在安装过程中分配客户端计算机的服务器名称 [英] how to assign server name of client machine during installing setup

查看:46
本文介绍了如何在安装过程中分配客户端计算机的服务器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好每一个



我有一个问题,我在Windows窗体中构建了一个项目c#

这是在处理stroing和retriving sql server 2008数据库中的数据

但是,对于构建过程我编码了我的机器的服务器名称现在我必须在客户端机器上安装它如何更改此服务器名称与客户端服务器名称其他明智的它会显示服务器未找到错误。

我需要更多建议





谢谢。

解决方案

你不应该硬编码服务器名称和连接字符串。在app.config中存储它们。所以在l tare date,如果你想改变连接字符串你只必须在app.config中进行更改,而不是在代码中进行更改。

在app.config中添加如下所示的部分

 <   appSettings  >  

< add key = ConnectionString value = 实际连接字符串 / >

< / appSettings >



使用以下代码从应用设置中读取值。



 System.Configuration.ConfigurationSettings.AppSettings [ConnectionString] 


使用app.config文件并更改manuaaly的连接字符串,app.config文件确实如此不需要重新编译。

O. r $ / $
使用以下SqlConnection

 SqlConnection MyConnection =  new  SqlConnection(  服务器=(本地);数据库=数据库名;集成安全性=真); 


将服务器名称存储在代码中不是一个好主意。您应该始终指定连接字符串您的app.config文件。这将使您能够更改连接字符串而无需对代码进行任何更改。您可以在构建安装程序时或安装完成后更改生产服务器详细信息的连接字符串。

Hello Every one

I have a problem that i built a project in windows form c#
which is dealing with stroing and retriving of data in sql server 2008 database
but , for building process i coded the server name of my machine now i have to install it in client machine how can i change this server name with client server name other wise it will shows a server not found error.
I need more suggestions


Thank you .

解决方案

You should not hard code server name and connection string.Store them in app.config instead.So that at l tare date, if you want to change connection string you only have to make change in app.config and not in your code.
add section like below in you app.config

<appSettings>
  
   <add key="ConnectionString" value="actual connection string" />
  
 </appSettings>


use below code to read value from app settings.

System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]


Use app.config file and change the connection string manuaaly, app.config file does not require to re-compile.
Or
Use following SqlConnection

SqlConnection MyConnection=new SqlConnection("Server=(Local); Database=DatabaseName; Integrated Security=True");


It is not a good idea to store the server name in code. You should always specify connection strings in your app.config file. This will enable you to change the connection string without making any changes to the code. You can change the connection string with your production server details at the time of building your setup or after the installation is complete.


这篇关于如何在安装过程中分配客户端计算机的服务器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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