两台或多台计算机中的SQL Server连接 [英] sql server connection in two or more computer

查看:82
本文介绍了两台或多台计算机中的SQL Server连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的项目...我只能在我的系统中访问数据库..

i想在其他系统中安装项目的安装文件...局域网已连接...然后我该怎么办?

i知道连接可以改变,但如何写连接字符串?

手动连接的任何变化?







问候

Anand Rajan

i developed as project...i can access database only in my system..
i want to install the setup file of project in other system...the LAN was connected ...then what can i do?
i know about connection can be change, but how to write the connection string ?
any changes in manually in computer connection ?



Regards
Anand Rajan

推荐答案

嗨Joy,



您可以使用web.config文件添加一个或多个连接字符串,

这是示例具有三个不同服务器的连接字符串。

Hi Joy,

You can use web.config file to add one or more connection string,
Here is the sample connection string with three different servers.
<connectionStrings>
<add name="localSystemDB" connectionString="Server=.\SQL2008;Database=DBName;User ID=username;Password=XXXXX;" providerName="System.Data.SqlClient"/>
<add name="remoteSystemDB" connectionString="Server=ipaddress\SQL2008R2;Database=DBName;ID=username;Password=XXXXX;" providerName="System.Data.SqlClient"/>
<add name="backupServer" connectionString="SERVER=backupsrvrIPaddress\SQL2008R2;DataBase=DBName;ID=username;Password=XXXXX;" providerName="System.Data.SqlClient"/>
 </connectionStrings>



在Code背后,您可以像这样使用


In Code behind you can use like this

connection_ = new SqlConnection(ConfigurationManager.ConnectionStrings["localSystemDB"].ToString()); //For localSystemDB
connection_ = new SqlConnection(ConfigurationManager.ConnectionStrings["remoteSystemDB"].ToString()); //For remoteSystemDB
connection_ = new SqlConnection(ConfigurationManager.ConnectionStrings["backupServer"].ToString()); //For backupServer



更新的解决方案:



正如您在web.config中提到的3个连接字符串,您的应用程序需要知道在运行时应该使用哪个连接字符串。

所以我们需要通过使用代码背后的代码来提及应用程序使用适当的连接字符串。

如果使用第一个代码,那么将使用localSystemDB连接字符串在应用程序中。

然而,如果您使用第二个连接字符串,您将从您的应用程序连接到remoteSystemDB。

如果您使用第三个连接字符串,那么您将被指向你的应用程序中的backupServer。







希望这会对你有所帮助。



问候,

RK


Updated solution:

As you have mentioned 3 connection string in your web.config, your application need to know which connection string should be used at runtime.
So we need to mention the application to use appropriate connection string by using the above code behind code.
If you use first code then "localSystemDB" connection string will be used in the applicaiton.
Whereas if you use second connection string you will be connected to "remoteSystemDB" from your application.
If you use third one then you will be pointed to "backupServer" from your application.



Hope this helps you a bit.

Regards,
RK


这篇关于两台或多台计算机中的SQL Server连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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