Connect to database using sql server remotely

有些话、适合烂在心里 提交于 2019-12-24 10:16:44

问题


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.


回答1:


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




回答2:


see:
http://connectionstrings.com/sql-server-2005

http://connectionstrings.com/sql-server-2005#p1



来源:https://stackoverflow.com/questions/8656066/connect-to-database-using-sql-server-remotely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!