Connect to database using sql server remotely

2019-08-10 02:30发布

问题:

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