SQL Server 2005 connections refresh

  • Hi Guys,

    I have an app that makes some restore operations. i'm having some problems with it, because when i put a database in single user mode , the database accepts the command and stays in single user mode, then, when i finish the connection (end the connection) to this database and connect to the master database to restore the database that was in single user mode, the app raises and error saing that database could not be putted in exclusive mode to do the restore...

    But i have already finished the connection that i had when i was in single user mode.

    I'm now connected to the Master database...

    I went to Management studio and i have seen that the connection takes some time to be ended... only with some refresh (F5) in the MS can make desappear the connection that i have already deleted... How can i refresh the connection settings in t-sql?

    Thank you

  • Are you disconnecting in your code? Or do you issue a "use master"? Or are you making a new connection to the instance?

  • Situation:

    I have a database named test.

    I'm connected to it , through this app.

    1) i put this database test in single user mode with success!

    2) Then i make run some stored procedures agains it (test database)

    3) Then i disconnect of this test database (ObjectConnection.close)

    4) i make a new connection but this time to master database

    5) i try to restore the test database, but i can not, because the other connection , as terminated but it seems that it is still in memory....

    How can i refresh this?

    Thank you

  • It should close quickly, but perhaps it doesn't close quick enough in your app. You don't need to disconnect. You can change context for the connection with a USE. Actually you don't need to connect to the db. you can connect to SQL Server and do this:

    USE MASTER

    ALTER DATABASE db1 SET SINGLE_USER

    RESTORE Database DB1 from DISK = 'c:\bak'

    ALTER DATABASE db1 SET MULTI_USER

    from the same connection

  • that solved my problem. thank you

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply