The process cannot access the file 'App_Data\HoaDB.mdf' because it is being used by another process.

Jose Puga 26 Reputation points
2022-05-11T19:28:49.343+00:00

Hello,
I need some help, I am trying to publish an ASP.net application that uses SQL tables, and every time I try to publish I got the message

Transformed web.config using C:\Users\Jose Puga\Documents\Visual Studio 2019\Projects\HOATIM\HOATIM\Web.Release.config into obj\Release\TransformWebConfig\transformed\web.config.
Adding database (C:\Users\Jose Puga\Documents\Visual Studio 2019\Projects\HOATIM\HOATIM\obj\Release\AutoScripts\ConnectionString-Deployment_SchemaAndData.sql)
Adding database (MSDeploy.dbFullSql/dbFullSql[@mutia keyza ='C:\Users\Jose Puga\Documents\Visual Studio 2019\Projects\HOATIM\HOATIM\obj\Release\AutoScripts\ConnectionString-Deployment_SchemaAndData.sql']/sqlScript)
Adding database (C:\Users\Jose Puga\Documents\Visual Studio 2019\Projects\HOATIM\HOATIM\obj\Release\AutoScripts\SysDBS-Deployment_SchemaAndData.sql)
Adding database (MSDeploy.dbFullSql/dbFullSql[@mutia keyza ='C:\Users\Jose Puga\Documents\Visual Studio 2019\Projects\HOATIM\HOATIM\obj\Release\AutoScripts\SysDBS-Deployment_SchemaAndData.sql']/sqlScript)
Auto ConnectionString Transformed obj\Release\TransformWebConfig\transformed\web.config into obj\Release\CSAutoParameterize\transformed\web.config.
Copying all files to temporary location below for package/publish:
obj\Release\Package\PackageTmp.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.targets(2601,5): Error : Copying file App_Data\HoaDB.mdf to obj\Release\Package\PackageTmp\App_Data\HoaDB.mdf failed. The process cannot access the file 'App_Data\HoaDB.mdf' because it is being used by another process.

The process cannot access the file 'App_Data\HoaDB.mdf' because it is being used by another process.

Any help will be appreciated.

Thanks..

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,251 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,691 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,686 Reputation points
    2022-05-13T21:34:06.02+00:00

    your localdb has the HoaDB.mdf mounted, so you can not copy it. you must unmount the database depending on which sql server database support you are using.

    0 comments No comments

  2. Lan Huang-MSFT 25,471 Reputation points Microsoft Vendor
    2022-05-16T02:42:16.973+00:00

    Hi @Jose Puga ,
    You can try closing the Sql Server process running the mdf file using task manager.
    Then close and reopen Visual Studio, copy the mdf file to the desired location.

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.