mark333...333...333
mark333...333...333

Reputation: 1360

My connection string using Windows authentication for SQL Server doesn't work

I'm having problems whenever I run my application, it says that the connection is wrong. The error is User '' has failed.

I think I didn't specify the user id and password but I don't know what is the user id and my password.

Here's my connection string

public SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=PayrollDB;Persist Security Info=True;");

Thanks in advance!

Upvotes: 1

Views: 24617

Answers (3)

error_handler
error_handler

Reputation: 1201

To allow windows authentication, you need to add integrated security set as tru in your connection string like this:

public SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=PayrollDB;Persist Security Info=True;Integrated Security=true;");

Upvotes: 1

Akshey Bhat
Akshey Bhat

Reputation: 8545

public SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=PayrollDB;Persist Security Info=True;Integrated Security=true;");

add Intergrated Security=true to connection string.

Upvotes: 6

MarPreSI
MarPreSI

Reputation: 21

You need to add the connection string attribute: Integrated Security = true. And this will work correctly.

Upvotes: 2

Related Questions