远程使用sql server连接数据库

moo*_*ine 1 sql sql-server connection

我使用c#语言完成了使用sql server和visual studio的程序.我想将数据库放在pc上,以及在其他PC上连接到该数据库的程序

我在App.config中使用此连接字符串:

<connectionStrings>
<add name="MWEConnectionString" connectionString ="integrated security=yes;initial catalog=MWDB;data source=.\sqlexpress"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)

我应该通过pc外部IP地址更改服务器名称吗?并根据sql server我应该使用Windows身份验证还是什么?我不知道怎么做.

The*_*yan 5

您应该使用Sql Server身份验证通过它的地址访问服务器.

您的连接字符串应如下所示:

connectionString="Data Source=192.168.0.5\SQL2008R2;Initial Catalog=MWDB;Persist Security Info=True;User ID=user;Password=password"
Run Code Online (Sandbox Code Playgroud)

(这只是一个例子,你的设置可能会有所不同).

另一个例子:

connectionString="Data Source=NAMEOFCOMPUTER\SQL2008R2;Initial Catalog=MWDB;Persist Security Info=True;User ID=user;Password=password"
Run Code Online (Sandbox Code Playgroud)

用于按名称访问服务器.

您可以从Visual Studio为应用程序生成连接字符串.从Database Explorer -> Connect to Database