Tuesday, April 28, 2009

.NET TableAdapter - connectionString fails for 'xxxx\ASPNET'

While working on getting an application copied from my development environment over to IIS for production testing I ran into an interesting database error.
System.Data.SqlClient.SqlException: Cannot open database "xxYourDBNameHerexx" requested by the login. The login failed.
Login failed for user 'xxComputerNamexx\ASPNET'.

My first thought was that I had wiped out a necessary database login or user when I accidentally wiped them all out the other day (you'll see how I recovered from this in another post), but it was much simpler to correct. There's a parameter in the connectionString, "Integrated Security" that's set to true when you create your TableAdapters in Visual Web Developer. This tells your application to login to SQL Server using the current logged in user's credentials, which seems to be those of IIS for a web application. From MSDN says this of the Integrated Security setting:
When false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication.

Simply change the value to false and then supply a username and password like so:

connectionString="Data Source=YOUR-COMPUTER\SQLEXPRESS;Initial Catalog=YourDBNameHere;Integrated Security=False;User ID=YourUserName;Password=YourPassword"


References: