none
SQL unable to copy file error 3

    Question

  • I'v built a program, and I used SQL. It worked fine but suddenly, without changing the code, I got this error message:

    Error 3 Unable to copy file "C:\Users\user\documents\visual studio 2010\Projects\Programm\Programm\App_Data\DataBase_log.ldf" to "bin\Debug\App_Data\DataBase_log.ldf". The process cannot access the file 'C:\Users\user\documents\visual studio 2010\Projects\Programm\Programm\App_Data\DataBase_log.ldf' because it is being used by another process.

    This is my connection string:

    private string ConnectionString()
    {
        return @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\App_Data\DataBase.mdf;Initial Catalog=DataBase.mdf;Integrated Security=True;User Instance=True";
    }

    I'm using SQL server 2008 and Visual studio 2010 with c# as my language program. I can't figure out what the problem is and I'd appreciate anyone who helps.


    • Edited by alonbar08 Sunday, September 08, 2013 2:35 PM
    Sunday, September 08, 2013 2:25 PM

Answers

  • Hello ,

    Your error seems logical as you are using the User Instance feature

    I would suggest to have a look at the "What is a RANU?" part of this article :

    http://blogs.msdn.com/b/sqlexpress/archive/2008/02/22/sql-express-behaviors-idle-time-resources-usage-auto-close-and-user-instances.aspx

    The author is Mike Wachal , maybe one of the persons who was knowing User Instances in the best way and surely the best ( over the world ) person  to explain this feature.

    The User Instance feature is depreciated since the release of SQL Server 2008 and the current version (2012) of SQL Server will be the last one supporting this feature. The problem with User Instance feature is that the developers have not understood the limits of this feature , flooding over the SQL Server Express Forum with threads showing that they have not studied the articles from Mike in the SQL Server Express Weblog.

    I gave up to use the user instances because they are not supported by the not-free editions of SQL Server. That's to say , if you have problems with the size of your databases , no salvation could be found in an upgrade towards a Web or Standard edition.

    It is why SQL Server 2012 is offering the LocalDB feature which could be considered as a replacement of the User Instance feature. But , as I had no time to test it really in a deep way , I prefer to be stuck to real databases. Moreover , I don't like to use databases which are local ( without remote connections except thru ASP.Net )

    About LocalDB ( available with SQL Server 2012 ) , I would suggest you to have a look at :

    http://blogs.msdn.com/b/sqlexpress/archive/2011/07/12/introducing-localdb-a-better-sql-express.aspx

    http://blogs.msdn.com/b/sqlexpress/archive/2011/10/28/localdb-where-is-my-database.aspx

    http://blogs.msdn.com/b/sqlexpress/archive/2011/11/28/using-localdb-in-visual-studio-2010.aspx

    Krzysztof ( who replaced Mike ) was a teacher as good as Mike about User Instance and LocalDB.

    A last advice : use SQL Server Management Studio ( Express or not ) to create a database or its associated objects ( views , stored procedures , ... ) rather than Visual Studio especially when it is an express edition. The connection string in the Express VS ( up to 2010 ) is using User Instance as default , you have to click on the Advanced button to obtain a new form where you will have to change the value of User Instance from True to False. VS 2012 is more clever as the default is not to use User Instance ( VS 2012 supports LocalDB, User Instance and the "normal way" , thanks the VS team , you have done a very good work ).

    You will discover other useful links in a sticky thread of the SQL Server Express Forum ( author : Mike Wachal )

    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?forum=sqlexpress&filter=alltypes&sort=lastpostdesc

    The another process which is annoying you is the RANU process which has the exclusive access to your .ldf file. If you want to do a copy of your file , see the excellent article from Mike Wachal

    http://blogs.msdn.com/b/sqlexpress/archive/2007/03/20/backup-and-restore-with-user-instances.aspx

    But it is not evident and easy to use.

    I could move your thread towards the SQL Server Express forum , but I prefer to wait for the agreement of the original poster. A move by a moderator avoids you to recreate a new post , to lose possibly posts and especially to let this thread dying in a not "appropriate" forum.

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.


    Sunday, September 08, 2013 5:43 PM