I’m getting an error when I try to compile or run the application.
Performing a simple tutorial, I worked at first but now when I generate the project F6 or try to run it, I always get the error
Error 1 Unable to copy
"C:\Projects\DatabaseExampleApp\DatabaseExampleApp\App_Data\northwnd.mdf"
to "bin\Debug\App_Data\northwnd.mdf". The process can not access the
file 'bin\Debug\App_Data\northwnd.mdf' because it is being used by
another process. DatabaseExampleApp
The first time when I run the app worked fine
I’m using:
- Visual Studio 2010 Professional
- SQL Server 2012 Express 64-bits
EDIT:
after:
- kill the
sqlservr.exe(is the file locker) - delete the files myself
northwnd.* northwnd_log.* - generate project F6
- run the app work fine
But I have a questions:
- how kill or unload the file
northwnd.mdfto avoid this problem?
The app compile after that but don’t run
You’re not showing us your connection string, but I’m assuming you’re using some kind of
AttachDbFileName=....approach.My recommendation for this would be: just don’t do that. It’s messy to fiddle around with
.mdffiles, specifying them directly by location, you’re running into problems when Visual Studio wants to copy that file around – just forget about all that.I would
CREATE DATABASE .....in Mgmt Studio)So I would put my database onto the SQL Server Express server instance, and then use a connection string something like this:
No messy file names, Visual Studio won’t have to copy around files at runtime or anything, your data is on the server and can be used and administered there – seems like the much cleaner and much nicer approach to me.