12 December 2013

Cannot open user default database. Login failed. Login failed for user 'THISCOMPUTER\COMPUTERNAME'.

Many newbies experience this type of error when they develop an ASP.NET website in their computer (laptop or desktop) and when they try to publish it on the web server (IIS Server) on a different machine or computer.

Actually, it happens because the default database is unavailable at the time of connection. Most reasons are maybe because the database has been detached or maybe because the only available connection is already being used by someone else or maybe because the database has been set to the RESTRICTED_USER state and the user has been denied access.

In many cases, one solution that works (sometimes) is when you run the aspnet_regsql.exe from the command line. But most of the time, I add applicationName attribute to the web.config and it works really great!

When you copy the application to the IIS server, the membership provider has been added in the web.config file but without an applicationName attribute. I suggest you add an “applicationName” attribute to your provider declaration like this:

<membership>
<providers>
<add name ....
.
.
.
.
applicationName="/yourWebApp" />

</providers>
</membership>
 
Just look in the aspnet_Application table to find out the application name that was used when creating the users/data during development.

No comments:

Post a Comment