1

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.mdf to avoid this problem?

The app compile after that but don't run

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
rkmax
  • 17,633
  • 23
  • 91
  • 176

1 Answers1

0

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 .mdf files, 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 the database on the SQL Server Express instance (CREATE DATABASE ..... in Mgmt Studio)
  • talk to the database by its logical name - not a physical file name

So I would put my database onto the SQL Server Express server instance, and then use a connection string something like this:

 Server=.\SQLEXPRESS;Database=MyShinyDatabase;Integrated Security=SSPI;

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459