Linq-to-Sql IIS7 Login failed for user ‘DOMAIN\MACHINENAME$’

Posted by cfdev9 on Stack Overflow See other posts from Stack Overflow or by cfdev9
Published on 2010-05-14T13:05:50Z Indexed on 2010/05/14 13:14 UTC
Read the original article Hit count: 821

Filed under:
|

I am encountering unexpected behaviour using Linq-to-sql DataContext. When I run my application locally it works as expected however after deploying to a test server which runs IIS7, I get an error Login failed for user ‘DOMAIN\MACHINENAME$’ when attempting to open objects from the DataContext.

This code explains the error, which breaks on the very last line with the error "System.Data.SqlClient.SqlException: Login failed for user".

        var connStr ="Data Source=server;Initial Catalog=Test;User Id=testuser;Password=password";

        //Test 1
        var conn1 = new System.Data.SqlClient.SqlConnection(connStr);
        var cmdString = "SELECT COUNT(*) FROM Table1";
        var cmd = new System.Data.SqlClient.SqlCommand(cmdString, conn1);
        conn1.Open();
        var count1 = cmd.ExecuteScalar();
        conn1.Close();

        //Test 2
        var conn2 = new System.Data.SqlClient.SqlConnection(connStr);
        var context = new TestDataContext(conn2);
        var count2 = context.Table1s.Count();

The connection string is not even using integrated security, so why is Linq-to-sql trying to connect as a specific user? If I change the server name in the connection string I get a different error so its using atleast part of the connection string, but apparently ignoring the UserId and Password. Very confused.

© Stack Overflow or respective owner

Related posts about iis7

Related posts about linq-to-sql