Question : Unable to open file dbname.mdf.

hi,

I have attached database to my application.. somewhere i forgot to close the connection(not sure).. when i run first time it runs and when i run second time it says

Error      1      Unable to copy file "C:\Users\xxxxxxxl\Documents\Visual Studio 2008\Projects\Sxxx\Sxxxxr\SDBName.mdf" to "bin\Debug\SDBName.mdf". The process cannot access the file 'bin\Debug\SDBName.mdf' because it is being used by another process.

This error is killin me. if i log off and login it works for first time. i know there is some silly mistakes.. Help is really appreciated..

Answer : Unable to open file dbname.mdf.

Obviously you need to go through the code to make sure you are closing all the datareaders and connections. Use the Using statement with connections so it makes sure the connection is closed after using. Also, use the finally blocks with try catch to make sure the connections are closed even if you get any errors.
Random Solutions  
 
programming4us programming4us