I am building a winform
based Desktop application in C#. I am using SQL Server Database in my application.
The application has an option of taking an archive, where I basically copy all the configuration files and data files ( *.mdf) into a Winzip Archive.
However, I am not able to copy the Database file *.mdf. It throws an exception :
"The process cannot access the file UserData.mdf because it is being used by another process"
I believe I am closing all the SQL connection, and perform manual Garbage collection via
GC.Collect()
.
But, this doesn't seem to work.
As a workaround, if I am able to kill the process sqlservr.exe from the Taskmanager, the file copy works fine.
I guess, there should be a better and a more elegant way of doing it. Any Idea how to proceed ?
Thanks Kiran
GC
.