locked
Error - Web deployment task failed Cannot attach the file as database RRS feed

  • Question

  • User-848295090 posted

    Web deployment task failed. (Cannot attach the file 'C:\Development\BG\App_Data\aspnet-BG-20130625133630.mdf' as database 'aspnet-BG-20130625133630'.)  

    My connectionstring is -

    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-bg-20130625133630;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-bg-20130625133630.mdf" />

    The web app is MVC 4 and EF

    Please help

    Thursday, June 27, 2013 10:58 AM

Answers

  • User-166373564 posted

    Hi,

    When you prepare to deploy a Web application project that uses one or more SQL Server databases, you can enter settings that specify database scripts that must run during deployment. These settings apply whether you deploy by using one-click publish or by using a Web deployment package. You could refer the procedures below to deploy database with web project, I think it will be good guide for you to deploy your project better,

    # How to: Deploy a Database With a Web Application Project

    http://msdn.microsoft.com/en-us/library/dd465343(v=vs.100).aspx

    Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 3, 2013 1:51 AM

All replies

  • User-345632295 posted

    This error means that the database file (\aspnet-BG-20130625133630.mdf) cannot be attach to the database server.

    The web deploy server should have more detail logging as to why the database attachment failed.  If you are hosting your site with a provider, you can always ask them to check the log.

    You can also consider deploying without the database and use alternative method to deploy your DB.

    Thursday, June 27, 2013 1:44 PM
  • User-848295090 posted

    I don't see anything on the logs on the Web Deploy Server. I don't think its getting that far in the process. I don't see a .mdf file in my App_Data folder either.

    Thursday, June 27, 2013 1:51 PM
  • User2122770105 posted

    quel est la version de SQL server utilisée pour le déploiement ?

    Thursday, June 27, 2013 1:56 PM
  • User-848295090 posted

    LocalDB

    Thursday, June 27, 2013 3:58 PM
  • User2122770105 posted

    Lorsque SQL server 2008 a été mis à jour sur mon PC, j'ai été obligé d'utiliser la version sql 2012. Les autre bases de données existantes étaient lues, mais plus aucune possibilité de les ouvrir ou de les modifier ou de créer d'autres tables dans ces bases. J'ai du recréer toutes mes tables avec la version 2012

    Thursday, June 27, 2013 4:51 PM
  • User1751268424 posted

    Hi,

    Are you deploying into production or IIS? LocalDb is not design to work with IIS, and also not recommended on production. You need to attach your aspnet-bg-20130625133630.mdf database to SQL server and change connectionString to this SQL Server.

    Have fun

    Thursday, June 27, 2013 7:42 PM
  • User2122770105 posted

    oui, j'aii des bases de données en local

    voici un exemple dans mon code behind

    je déclare en private mes objets en haut de page

        Connectb.ConnectionString = "Data Source=|DataDirectory|\00000000000.sdf"
            cmdtb = New SqlCeCommand("SELECT * FROM myBD")
            Connectb.Open()
            cmdtb.Connection = Connectb
            Adapttb.SelectCommand = cmdtb
            Adapttb.Fill(datsettbmemb, "myBD")
            bidingtbmemb.DataSource = datsettbmemb
            bidingtbmemb.DataMember = "myBD"
    Friday, June 28, 2013 4:18 AM
  • User-848295090 posted

    @jsiahaan - My source database is LocalDB. I am deploying my application into production. In production I am running IIS 7.5 & SQL Server 2012 Express. Is that a problem?

    Friday, June 28, 2013 11:21 AM
  • User2122770105 posted

    Je ne pense pas ce soit un problème, mais il semblerai que l'extension .MDF ne soit plus supporté par la version de SQL 2012. Moi j'ai créer une nouvelle base qui a mis l'extension .SDF et je n'ai plus eu de problème.

    Mais je ne peux plus ouvrir les bases avec l'extension .MDF, ni modifier les tables ou ajouter un champ. Par contre aucun problème sur les

    extensions .SDF 

    C'est pour ça que je pense que le dépoiement ne se fait plus.

    Fait un essai de créer une base avec .SDF. 

    Friday, June 28, 2013 1:11 PM
  • User1751268424 posted

    Hi,

    You can use both localDb inside a project while develop, and you can use SQL Express both on IIS 7.5 and development . There is no problem on it.

    Have fun

    Friday, June 28, 2013 8:02 PM
  • User-166373564 posted

    Hi,

    When you prepare to deploy a Web application project that uses one or more SQL Server databases, you can enter settings that specify database scripts that must run during deployment. These settings apply whether you deploy by using one-click publish or by using a Web deployment package. You could refer the procedures below to deploy database with web project, I think it will be good guide for you to deploy your project better,

    # How to: Deploy a Database With a Web Application Project

    http://msdn.microsoft.com/en-us/library/dd465343(v=vs.100).aspx

    Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 3, 2013 1:51 AM
  • User-848295090 posted

    I realized scripts is the only way to go. My manager and I argued which is better attach/detach database or scripts.

    Wednesday, July 3, 2013 8:29 AM