问题描述
我已经使用c#语言完成了使用sql server和visual studio的程序。
我想将数据库放在pc上,并将程序连接到其他PC上的数据库
我在App.config中使用这个连接字符串:
< connectionStrings>
< add name =MWEConnectionStringconnectionString =integrated security = yes; initial catalog = MWDB; data source = .\sqlexpress/>
< / connectionStrings>
我应该通过pc外部ip地址更改服务器名称吗?
和根据sql server应该使用windows身份验证还是什么?
我不知道该怎么做。
您应该使用Sql访问服务器的地址服务器身份验证。
您的连接字符串应如下所示:
connectionString =Data Source = 192.168.0.5\SQL2008R2;初始目录= MWDB; Persist安全信息= True;用户ID =用户;密码=密码
(这只是一个例子,您的设置可能不同。)
connectionString =Data Source = NAMEOFCOMPUTER\SQL2008R2; Initial Catalog = MWDB; Persist Security Info = True; User ID = user; Password = password
$ b p>您可以从Visual Studio为应用程序生成连接字符串。从数据库浏览器 - >连接到数据库
I have finished a program using sql server and visual studio using c# language .
I want to put the database on pc and the program that connected to that database on other PCs
I'm using this connection string in App.config :
<connectionStrings>
<add name="MWEConnectionString" connectionString ="integrated security=yes;initial catalog=MWDB;data source=.\sqlexpress"/>
</connectionStrings>
Should I change server name by pc external ip address?and according to sql server Should I use windows authentication or what?I don't know how to do it.
解决方案 You should access the server by it's address by using Sql Server authentication.
Your connection string should look something like this:
connectionString="Data Source=192.168.0.5\SQL2008R2;Initial Catalog=MWDB;Persist Security Info=True;User ID=user;Password=password"
(this is just an example, your settings will probably be different).
Another example:
connectionString="Data Source=NAMEOFCOMPUTER\SQL2008R2;Initial Catalog=MWDB;Persist Security Info=True;User ID=user;Password=password"
for accessing the server by name.
You can generate a connection string for your application from Visual Studio. From Database Explorer -> Connect to Database
这篇关于使用sql server远程连接到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!