none
backup database by its own process RRS feed

  • Question

  • Hi

     

    in same app, I am using SMO to backup my database, but it failed if this database is using with my same app, the system can not open database file, my code can backup other database file, any suggetions?

     

    Thanks

    Thursday, September 11, 2008 7:49 PM

All replies

  • Hello,

     

    I suppose that you are refering to this post

    http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3860589&SiteID=1

     

    Try to put just before

    sqlBackup.SqlBackup(sqlServer);

    this line :

    sqlServer.ContextConnect.Disconnect();

    that's sometimes working

    ( you have opened your connection with the line :

    db = sqlServer.Databases["RegServer"]

    and often, the connection is closed after 30 seconds.

    the Disconnect() forces the close of the database ( works badly in case of user instance )

     

    Have a nice day

    Thursday, September 11, 2008 9:24 PM
    Moderator
  • Thank you

     

    but no lucky, it does not work either, any other suggestions?

     

    Cheers!

     

    Friday, September 12, 2008 2:30 PM
  • Further information, in my app I use linq to access database, if I don't launch my app, Sql management studio express works fine with database, after app run, if I operate this database from Sql management studio express, I got error message

     

    Cannot show requested dialog. (Microsoft.SqlServer.Express.SqlMgmt)

    ------------------------------

    Unable to open the physical file "C:\Dev\networkserver\RegServer\RegServer\bin\Debug\RegServer.mdf". Operating system error 32: "32(error not found)". (Microsoft SQL Server, Error: 5120)

    ------------------------------

    and then even I closed my app, if I operate this database from Sql management studio express, I still got error message

     

    Cannot show requested dialog. (Microsoft.SqlServer.Express.SqlMgmt)

    ------------------------------

    An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.Express.ConnectionInfo)

    ------------------------------

    Database 'C:\DEV\NETWORKSERVER\REGSERVER\REGSERVER\BIN\DEBUG\REGSERVER.MDF' cannot be opened due to inaccessible files or insufficient memory or disk space.  See the SQL Server errorlog for details. (Microsoft SQL Server, Error: 945)

    ------------------------------

    any helps please

     

    Thanks

    Friday, September 12, 2008 4:13 PM
  •  

    Hi,

     

    I would like to know more about what your App does. But atleast for the code, before you do the backup, you can do the following ( Just to see if it is only connection issue).

    /* your code*/

    db.UserAccess = DatabaseUserAccess.Single;

    db.Alter(TerminationClause.RollbackTransactionsImmediately);

     

    This is basically getting the database into single user model. Anyway, if your App isnt big, I would like to know what you do just before you wrote the backup code using SMO. If you can raise a 'microsoft connect' bug we can track it from there as well.

     

    Regards

    Vinod

    Saturday, September 13, 2008 1:49 AM
    Answerer
  • thanks

     

    after I add these following your instruction, it works, but I have to add KillAllProcesses, then after restore, my app can not query the database via linq, anyway can make my database work properly after retore?

     

    Database db = sqlServer.Databases[currentData];

    sqlServer.KillAllProcesses(db.Name);

    db.DatabaseOptions.UserAccess = DatabaseUserAccess.Single;

    db.Alter(TerminationClause.RollbackTransactionsImmediately);

     

    after this the first query I got this error: A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)

     

    and then second time all works, too strange

    Monday, September 15, 2008 3:26 PM