CREATE DATABASE permission denied in database 'master'. A database with the same name exists

Tapas Bose picture Tapas Bose · Mar 21, 2012 · Viewed 12.3k times · Source

I was running my application in Visual Studio 2010 Application Server, but now I have changed it to use IIS Local Server, then everything crushed. I am getting following error:

System.Data.SqlClient.SqlException: CREATE DATABASE permission denied in database 'master'.
An attempt to attach an auto-named database for file D:\Code\EMSApplication\EMSApplication.Web\App_Data\ASPNETDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

I have changed the setting of Application Pool of the Default Web Site of IIS to Classic .NET AppPool.

enter image description here

Also changed the Identity of the Classic .NET AppPool to LocalSystem.

enter image description here

I also set the permission of the NETWORK SERVICE to the Full

enter image description here

The connection string is:

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.mdf;Integrated Security=True

But none of them worked. I am still getting that error. Any suggestion will be very helpful to me.

Thanks.


I am using SQL Server 2008 Express which comes with the installation of Visual Studio 2010.

Answer

Chris Shain picture Chris Shain · Mar 21, 2012

The problem is, pretty clearly, that you already have a database named ASPNETDB attached to that SQL Server instance. My assumption is that the VS development web server is still running, and that is what has the database attached. If so, just shut it down and try an IIS restart, and you should be good. If that doesn't do it, go and download SSMS Express, connect to your local SQLExpress instance, and try to detach the existing database from there.