Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 587
HungDQ Avatar asked Nov 07 '22 20:11

HungDQ


1 Answers

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

like image 103
Roxy'Pro Avatar answered Nov 15 '22 07:11

Roxy'Pro