简体   繁体   中英

Difficulty Connect to SQL Server Express on LAN

I'm having trouble connecting to a SQL Server on a machine in our LAN.

i have done the following :

1.) Made the IP of the machine running the Server 10.0.0.7 and made the IP of the other machines on the LAN IP 10.0.0.X . There is no internet on the LAN(and it will stay that way), changeing IP is permitted.

2.)Enabled remote connection by doing This

3.)Used the appropriate connection string.

Now my only Question that remains is regards to the connection string of those who wish to connect on the server, here is the current Con-string:

string sConnection = @"Server=10.0.0.7\MARNUS-PC\MARNUS_HOME; User ID=MARNUS-PC\MARNUS_HOME; Password=somepassword; Initial Catalog=TestDB;";

My questions are :

1.)What do i put the Server portion? here is my Server name and instance name acording to the management studio - Server name : MARNUS-PC\\MARNUS_HOME , Instance name : MARNUS_HOME.

2.)What do i use as user ID? I wish to use Windows authentication instead of sql server authentication(i have enabled both on server), so how should the connection string change and how to do i allow a user from the server's side on the management studio(if needed)?

3.)I asume if I use Windows authentication i do not need the password part of the Con-String?

I apologize for all the questions,but i was taught MS Access and is now making the switch to SQL Server by myself.

Your connection string must be something like....

string sConnection = @"Server=MARNUS-PC\InstanceName; User ID=MARNUS-PC\MARNUS_HOME; Password=somepassword; Initial Catalog=TestDB;";

Instance name is the Sql Server Instance name .

If you are not Sure about your instance name execute the following statement in your Sql Server Management Studio

SELECT @@SERVERNAME

It will return the [ServerName\\InstanceName] you can pass the whole returned string to your connection string are your Server name Server=ServerName\\InstanceName;

Windows Authentication

To use windows authentication you will have to a connection string something like this..

 string sConnection = @"Server=MARNUS-PC\InstanceName;  Initial Catalog=TestDB; integrated security=SSPI";

The IP address identifies the computer, so you wouldn't use both the IP address and the computer name. You can use the IP address in the server setting:

Server=10.0.0.6\MARNUS_HOME;

or you can use the computer name:

Server=MARNUS-PC\MARNUS_HOME;

You are correct that you shouldn't specify any password when you are using windows authentication, and you shouldn't specify any user name either, but you need to specify that you are using it:

Trusted_Connection=Yes;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM