question

JosePuga-2247 avatar image
0 Votes"
JosePuga-2247 asked ErlandSommarskog commented

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

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[@path='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[@path='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..

sql-server-generaldotnet-aspnet-generaldotnet-aspnet-webforms
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You should probably add an ASP .NET tag. As an SQL Server person I can only look at this and ask "What are you doing?" Apparent there is already a database in the place where you are copying the file, and apparently that database is already attached to an SQL Server instance.

But for an SQL Server person like me, this is a very alien way to deploying a databaes, and it also a very odd path for an SQL Server database.

But I have hinch that Visual Studio does a good job of confusing everyone by having its own pattern, so neither the developer nor the SQL Server person reallhy knows what is going on.

0 Votes 0 ·
Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered

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.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LanHuang-MSFT avatar image
0 Votes"
LanHuang-MSFT answered ErlandSommarskog commented

Hi @JosePuga-2247,
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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

That's a bit brutal. It would be better to stop the instance through SQL Server Configuration Manager. Or through the sqllocaldb utility if it is a localDB instance.

0 Votes 0 ·