Leron
Leron

Reputation: 9846

Integrated Security=true is trying to log me with my windows credentials even though I want to use SQL authentication

I'm working on ASP.NET Web Forms application, using standard ADO.NET for quering the database. Since today I've been developing on my local machine, using local resources (including local isntance of SQL Server 2008) and I use a very simple connections string plus Windows auth to connect to my database:

<add name="MyConn" connectionString="Data Source=MY-PC\SQLEXPRESS;Initial 
Catalog=MyDataBaseName;Integrated Security=true;"/>

But today I wanted to remove to a remote SQL SERVER so I changed my connection string accordingly:

<add name="MyConn" connectionString="Data Source=TheRemoteServer;
Initial Catalog=MyDataBaseName;User Id=MyId;Password=MyPassword;
Integrated Security=true;"/>

and when I try to connect to the database, when I reach :

 try
 {
   connection.Open();

I get an error that connection can not be established for user and here come my Windows user instead the ID I've provided in the connection string. However if I set Integrated Security=false; (to False) everything starts working. I don't know why. It seems strange and since it obviously has something to do with security I'm bothered leaving it like that. So what are my options here?

Upvotes: 2

Views: 1831

Answers (2)

apomene
apomene

Reputation: 14389

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.

SqlCredential is a more secure way to specify credentials for a connection that uses SQL Server Authentication (Integrated Security=false).

SQL Credential

Upvotes: 3

M.Ali
M.Ali

Reputation: 69494

Just use the following:

<add name="MyConn" connectionString="Data Source=TheRemoteServer;
Initial Catalog=MyDataBaseName;User Id=MyId;Password=MyPassword;"/>

or

<add name="MyConn"  ConnectionString="Server=myServerName\myInstanceName;
Database=myDataBase;User Id=MyId;Password=myPassword;"/>

Upvotes: 0

Related Questions