1

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.

Tapas Bose
  • 28,796
  • 74
  • 215
  • 331
  • I'm not sure whether to consider this off-topic or not... It isn't really a programming question (more of a system admin question), but it's probably something that every developer that works with a database should know how to do. – M.Babcock Mar 21 '12 at 16:37
  • You know what you haven't included here? Any information about the SQL server or existing databases. Don't you think that would be pertinent, particularly considering the wording of the error message? – cHao Mar 21 '12 at 16:37
  • @cHao I have updated my answer. The database is Sql Server 2008 which comes with Visual Studio 2010. – Tapas Bose Mar 21 '12 at 16:42
  • And what about existing databases? – cHao Mar 21 '12 at 16:43
  • Have you tried using a different DB name than `ASPNETDB`? Something more specific would probably be better anyway. – M.Babcock Mar 21 '12 at 16:44
  • 1
    Whow, that is a useless lof of pictures instead of just providing the info that is relevant according to the error message - the list of attached databases with name. – TomTom Mar 21 '12 at 16:48
  • ... or just stopping the VS debug server? It's a little icon in the system tray next to the clock. – Chris Shain Mar 21 '12 at 16:48
  • Considering that the error message says " A database with the same name exists," in it, could you show us the databases that are on your SQL Server? Chances are you're trying to add something that has already been added. Chrish Shain's answer would be good reading for you. – Jeremy Pridemore Mar 21 '12 at 16:55

1 Answers1

6

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.

Chris Shain
  • 50,833
  • 6
  • 93
  • 125