[英]WCF : remote SQL Server 2005 database connection
I'd like to know how to link my WCF application with a remote SQL Server database. 我想知道如何将WCF应用程序与远程SQL Server数据库链接。 By remote, I mean that is on the same network than me but not on the same computer/project.
远程是指与我位于同一网络上,但不在同一计算机/项目上。 I've the controll of the computer where the database is stored on.
我控制着存储数据库的计算机。
What I've done so far : create my WCF application and try to add an ADO.NET connection. 到目前为止,我已经完成了什么:创建WCF应用程序,并尝试添加ADO.NET连接。 My issue : where to find the name of the server ?
我的问题:在哪里可以找到服务器的名称? (and also : is it the good way to proceed ?).
(并且:这是进行下一步的好方法吗?)。
Thanks ! 谢谢 !
where to find the name of the server?
在哪里可以找到服务器的名称?
Three options: 三种选择:
SqlDataSourceEnumerator
(not a fan of this option, to be honest) SqlDataSourceEnumerator
发现sql服务器(说实话,不是此选项的支持者) Conntion string should look like 连接字符串应如下所示
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;Password=myPassword;
In Place of myServerName you can use IPAdress of machine 可以使用机器的IPAdress代替myServerName
I suggest you add connectionString
in the Web.config
file of the application 我建议您在应用程序的
Web.config
文件中添加connectionString
<add name="connectionString"
connectionString="Data Source=ServerName/PC-Name;Initial Catalog=DatabaseName;User ID=userid;Password=pass"
providerName="System.Data.SqlClient" />
Use the connection string
in your code/Logic 在代码/逻辑中使用
connection string
string conn = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.