Friday 16 August 2013

Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

I started getting this message, seemingly randomly, when running my integration tests.

The integration tests were using EF 5.0 to connect to my local SQL Server instance.

A lot of the blogs on this error are focused on how to resolve this issue given that you are connecting to a SQL Server instance on another machine, another domain - in which the error and its message seems relevant.

However, given that I was connecting locally, I couldn't make sense of it.

I then realised that VS2012 had created an App.Debug.config and App.Release.config in addition to the App.config file I was editing.

I was alternating running the tests in Release and Debug modes to see if that alone was causing the problem, but the error occurred in both modes.

To try and isolate the problem, I removed the EF connection string from all app.configs in the Testing project.

Then ran the tests in Debug mode - as expected it complained that the connection string was missing.

So I put it back in - exactly as it was previously.

And the error went away - WTF???

There was some talk of this error being caused by cached credentials - this would imply that at some stage, my windows login was cached and that the Test Runner is using that to login to SQL Server - but that shouldn't be a problem because its the same account I use to login via SQL Server Manager anway...

So I have no idea what has caused the problem...nor a reliable solution to make it go away.

It did happen again though - same project - but different code base version; I simply deleted the connection string from the App.Debug.config file, ran the tests, it complained about missing connection string, I added it back just as it was...and VOILA - the 'Login failed' error doesn't occur and the tests run as per normal...

No comments:

Post a Comment