Categories
asp.net asp.net-4.0 sql-server-2008 unc vb.net

An attempt to attach an auto-named database for file ….database1.mdf failed

I am getting the following error while debugging my visual studio 2010 website:

An attempt to attach an auto-named database for file C:\Users…\Desktop\Dpp2012New\App_Data\dppdatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file C:\Users…\Desktop\Dpp2012New\App_Data\dppdatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Here is my connection string from my web.config:

<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient"/>
<add name="ConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dppdatabase.mdf;Integrated Security=SSPI"
providerName="System.Data.SqlClient"/>
</connectionStrings>

And I access it from my website as:

Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString

The stacktrace shows the error line as:

 Dim conn As New SqlConnection(connectionString)
Dim dr As SqlDataReader
conn.Open() 'This is the error line as per stacktrace

I have given the needed permissions to the above folder so it can not be the ” or specified file cannot be opened” issue. If we look at all the posts related to the same error in this forum, clearly the profoundness of this error can be found out. However, none of the solutions solves my issue.
Some of the resources which I have tried are:

  1. http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx
  2. http://blogs.msdn.com/b/webdevelopertips/archive/2010/05/06/tip-106-did-you-know-how-to-create-the-aspnetdb-mdf-file.aspx
  3. http://forums.asp.net/t/1033225.aspx

I eagerly await a solution.