Search code examples
c#sqlsqlconnection

Login failed for user domain\user


I just started with writing SQL in visual studio and combining it with C#. I made a localdatabase in my visual studio, but somehow I cant connect to it. It tells me login failed for user domain\user

I am using this code: using (SqlConnection dbConnection = new SqlConnection("Data Source = (LocalDB)\\MSSQLLocalDB;Database=Employee;Integrated Security=SSPI;User ID=domain\\user;Password=mypassword"))

Am I missing something?

When I open the Server Explorer in Visual Studio I can see Azure, Data Connections and Servers with my local PC in it.

Any help is much appreciated! Thanks in advance


Solution

  • Remove Integrated Security=SSPI; from your connection string. If you want to log in with username/password you should not specify that you want to use integrated security at the same time.

    Alternatively remove the username and password and use integrated security.

    Also make sure that the user is actually created in the database, and that it has the right permissions.