Sql-server – Why can’t I log into SQL Server using Windows Integrated Security

sql serversql-server-2008

I'm trying to write a small app that will log into SQL Server to perform some admin functions. When I connect to SQL Server using the following connection string, I can log in fine:

Data Source=Localhost\SqlExpress;Initial Catalog=PeteDb;User Id=sa;Password=test;

However when I want to use integrated:

Data Source=Localhost\SqlExpress;Integrated Security=True;MultipleActiveResultSets=True"

A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 26 – Error Locating Server/Instance
Specified)

How can this be solved? I am in the list of logins.

Best Answer

Do you need to specify the Initial catalog in the 2nd connection string? Something like this:

Data Source=Localhost\SqlExpress;Initial Catalog=PeteDb;Integrated Security=True;
Related Topic