Problem publishing web site ASP.NET 4.0

2.6k Views Asked by At

I'm trying to publish a simple site with Visual Studio 2010. I use Web Deploy. I'm getting the following error:

Error 1 Web deployment task failed.(Object of type 'dbFullSql' and path 'Data Source=.\SQLEXPRESS;AttachDbFilename=c:\documents and settings\tavi\my documents\visual studio 2010\Projects\WebApplication3\WebApplication3\App_Data\aspnetdb.mdf;Integrated Security=True;User Instance=True' cannot be created.)

Object of type 'dbFullSql' and path 'Data Source=.\SQLEXPRESS;AttachDbFilename=c:\documents and settings\tavi\my documents\visual studio 2010\Projects\WebApplication3\WebApplication3\App_Data\aspnetdb.mdf;Integrated Security=True;User Instance=True' cannot be created. Cannot connect to the database 'c:\documents and settings\tavi\my documents\visual studio 2010\Projects\WebApplication3\WebApplication3\App_Data\aspnetdb.mdf'. An attempt to attach an auto-named database for file c:\documents and settings\tavi\my documents\visual studio 2010\Projects\WebApplication3\WebApplication3\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. 0 0 WebApplication3

I deleted the aspnetdb.mdf file using SQL Server Management Studio, and I'm still getting this error. What could be wrong?

1

There are 1 best solutions below

0
On

I ran into the same issue (but with SQL Server instead of aspnetdb.mdf) and this a solution that worked for me. I know that the question is old, but I am posting this for future references.

Be aware that using this solution your database will be dropped before the new database is deployed. Thus is is a unsafe operation and does only fit for development.

First off all I think the option of dropping the database should be available through a checkbox in the project settings, but instead we are forced to edit the project file manually. The entry to the is the article How to: Deploy a Database With a Web Application Project. In the section "Redeploying By Using Automatically Generated Scripts" we can read that setting ScriptDropsFirst=True in the PreSource element of the automatically generated script the target database will be dropped before the new database is deployed.

So, to do this: Open the .csproj file in notepad, find the section called PreSource (one for each configuration debug/release/...) and add the ScriptDropsFirst="True" element to it so that the entire xml tag is on the form <PreSource Path="Data Source=LOCALHOST\SQLEXPRESS%3bInitial Catalog=myDB%3bIntegrated Security=True" ScriptSchema="True" ScriptData="False" CopyAllFullTextCatalogs="False" ScriptDropsFirst="True" />

Using these settings I am able to re-publish my databases as I wish.


Side note: This solution will hardly work in a production environment where you cannot drop your databases as soon as you need to update the solutions. Instead I would opt to use custom scripts to aid the update, as introduced in the section "Deploying Database Changes by Using Custom Scripts" in the same article.