HungDQ
HungDQ

Reputation: 325

SQL server management studio - How to connect to SQL server using connection string?

I cannot connect to SQL Server by using SQL Server Management Studio. I have a connection string:

 <add name="AccountConnStr" connectionString="Data Source=MyIP;Initial Catalog=nvm;Persist Security Info=True;User ID=myID;Password=myPassWord" providerName="System.Data.SqlClient" />

I have tried to connect by entering myIP to Servername, MyID to Login and myPassword to password but still unable to connect. This is the result:

enter image description here

Does anyone has ideas ?

Thank you very much.

Upvotes: 6

Views: 41432

Answers (2)

Abdul Samad
Abdul Samad

Reputation: 39

try to put IP address

<add key="AccountConnStr" value="Data Source=192.168.2.1\SQLSERVERNAME;Initial Catalog=nvm;Persist Security Info=True;User ID=myDomain\myUsername;Password=myPassword"/>

and put IP and Domain in etc/Host File and also try to test ping your server ip is it reachable from your computer . Enable remote connections on the instance of SQL Server that you want to connect to from a remote computer. and make sure that checkbox Allow remote connections to this server is selected .

Upvotes: 0

Roxy&#39;Pro
Roxy&#39;Pro

Reputation: 4454

Because you are using Username and a Password to connect to a database, you should change your connection string to look something like this:

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=False;
User ID=myDomain\myUsername;Password=myPassword;

If you are wondering why:

Integrated Security When false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication. Recognized values are true, false, yes, no, and sspi (strongly recommended), which is equivalent to true. If User ID and Password are specified and Integrated Security is set to true, the User ID and Password will be ignored and Integrated Security will be used.

P.S

If this is not helping then you may check this also:

Make sure your database engine is configured to accept remote connections:

Start > All Programs > SQL Server 2005 > Configuration

Tools > SQL Server Surface Area Configuration Click on Surface Area

Configuration for Services and Connections Select the instance that is

having a problem > Database Engine > Remote Connections Enable local and remote connections Restart instance

You may need to create an exception on the firewall for the SQL Server instance and port you are using:

Start > Run > Firewall.cpl Click on exceptions tab Add sqlservr.exe

(typically located in C:\Program Files (x86)\Microsoft SQL

Server\MSSQL.x\MSSQL\Bin, check your installs for the actual folder

path) and port (default is 1433) Check your connection string as well

Upvotes: 2

Related Questions