Have you received the following error:
Login failed for user ‘Domain\Username’.
SQLExpress database file auto-creation error
In Visual Studio 2005 or 2008 when trying to run a web site that auto-creates an ASP.NET database. Or perhaps you’ve gotten the error when simply right clicking on App_Data and trying to add a new SQL Server database usually named ASPNETDB.MDF?
After wasting a day of my time verifying things such as:
Does my windows username have dbcreate access in SQL Express?
Does my global web.config or machine.config have something wrong in the connectionStrings section? Perhaps LocalSqlServer got misconfigured in the past.
In the end I discovered that the reason was Vista’s user account control. I simply needed to to right click on my Visual Studio icon and select “Run as Administrator”, then everything worked and the error went away.
This is why it might work fine if you are running the ASP.NET web application in IIS, but not when running under a DB admin authorized windows administrator account in Visual Studio.
Another tip: If you are having any sort of strange error or problem in Visual Studio or with running sites, just exit Visual Studio and run it again as administrator.