How to disconnect all connections of a Database.

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I write a restore program to restore a database.
But it must stop all connecions to the database before resotre.
How can I stop all connecions to the database by program?
 
ad,

There is no way to do this out of the box. If anything, it depends on
the database. Most likely, you will have to use some sort of administrative
interface (there might or might not be one you can access programatically,
depending on the database) to kick everyone off.

Which database are you using?

Hope this helps.
 
If you are using SQL Server...

Take it offline:
http://developer.mimer.com/documentation/html_82/Mimer_SQL_Reference_Manual/SQL_Statements84.html

Restore it:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ra-rz_25rm.asp

--

Derek Davis
(e-mail address removed)

Nicholas Paldino said:
ad,

There is no way to do this out of the box. If anything, it depends on
the database. Most likely, you will have to use some sort of
administrative interface (there might or might not be one you can access
programatically, depending on the database) to kick everyone off.

Which database are you using?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

ad said:
I write a restore program to restore a database.
But it must stop all connecions to the database before resotre.
How can I stop all connecions to the database by program?
 
A better link for the offline part:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_da-di_8c32.asp

--

Derek Davis
(e-mail address removed)

carion1 said:
If you are using SQL Server...

Take it offline:
http://developer.mimer.com/documentation/html_82/Mimer_SQL_Reference_Manual/SQL_Statements84.html

Restore it:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ra-rz_25rm.asp

--

Derek Davis
(e-mail address removed)

Nicholas Paldino said:
ad,

There is no way to do this out of the box. If anything, it depends on
the database. Most likely, you will have to use some sort of
administrative interface (there might or might not be one you can access
programatically, depending on the database) to kick everyone off.

Which database are you using?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

ad said:
I write a restore program to restore a database.
But it must stop all connecions to the database before resotre.
How can I stop all connecions to the database by program?
 
Thanks,
I use the codes below, but it fail when there are some users accessing the
database

------------------------------------------------------------------------------------------------------------------
C. Take a database offline
This example takes the sales database offline if there are no users
accessing the database.

USE master
EXEC sp_dboption 'sales', 'offline', 'TRUE'

carion1 said:
A better link for the offline part:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_da-di_8c32.asp

--

Derek Davis
(e-mail address removed)

carion1 said:
If you are using SQL Server...

Take it offline:
http://developer.mimer.com/documentation/html_82/Mimer_SQL_Reference_Manual/SQL_Statements84.html

Restore it:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ra-rz_25rm.asp

--

Derek Davis
(e-mail address removed)

Nicholas Paldino said:
ad,

There is no way to do this out of the box. If anything, it depends
on the database. Most likely, you will have to use some sort of
administrative interface (there might or might not be one you can access
programatically, depending on the database) to kick everyone off.

Which database are you using?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I write a restore program to restore a database.
But it must stop all connecions to the database before resotre.
How can I stop all connecions to the database by program?
 
Well you could find who is connected to the db in question with sp_who and
then kill those open connections.

--

Derek Davis
(e-mail address removed)

ad said:
Thanks,
I use the codes below, but it fail when there are some users accessing the
database

------------------------------------------------------------------------------------------------------------------
C. Take a database offline
This example takes the sales database offline if there are no users
accessing the database.

USE master
EXEC sp_dboption 'sales', 'offline', 'TRUE'

carion1 said:
A better link for the offline part:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_da-di_8c32.asp

--

Derek Davis
(e-mail address removed)

carion1 said:
If you are using SQL Server...

Take it offline:
http://developer.mimer.com/documentation/html_82/Mimer_SQL_Reference_Manual/SQL_Statements84.html

Restore it:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ra-rz_25rm.asp

--

Derek Davis
(e-mail address removed)

in message ad,

There is no way to do this out of the box. If anything, it depends
on the database. Most likely, you will have to use some sort of
administrative interface (there might or might not be one you can
access programatically, depending on the database) to kick everyone
off.

Which database are you using?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I write a restore program to restore a database.
But it must stop all connecions to the database before resotre.
How can I stop all connecions to the database by program?
 
Thanks,
Could you give me an example?


carion1 said:
Well you could find who is connected to the db in question with sp_who and
then kill those open connections.

--

Derek Davis
(e-mail address removed)

ad said:
Thanks,
I use the codes below, but it fail when there are some users accessing
the database

------------------------------------------------------------------------------------------------------------------
C. Take a database offline
This example takes the sales database offline if there are no users
accessing the database.

USE master
EXEC sp_dboption 'sales', 'offline', 'TRUE'

carion1 said:
A better link for the offline part:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_da-di_8c32.asp

--

Derek Davis
(e-mail address removed)

If you are using SQL Server...

Take it offline:
http://developer.mimer.com/documentation/html_82/Mimer_SQL_Reference_Manual/SQL_Statements84.html

Restore it:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ra-rz_25rm.asp

--

Derek Davis
(e-mail address removed)

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote in message ad,

There is no way to do this out of the box. If anything, it depends
on the database. Most likely, you will have to use some sort of
administrative interface (there might or might not be one you can
access programatically, depending on the database) to kick everyone
off.

Which database are you using?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I write a restore program to restore a database.
But it must stop all connecions to the database before resotre.
How can I stop all connecions to the database by program?
 
kill [spid]

--

Derek Davis
(e-mail address removed)

ad said:
Thanks,
Could you give me an example?


carion1 said:
Well you could find who is connected to the db in question with sp_who
and then kill those open connections.

--

Derek Davis
(e-mail address removed)

ad said:
Thanks,
I use the codes below, but it fail when there are some users accessing
the database

------------------------------------------------------------------------------------------------------------------
C. Take a database offline
This example takes the sales database offline if there are no users
accessing the database.

USE master
EXEC sp_dboption 'sales', 'offline', 'TRUE'

"carion1" <[email protected]>
¼¶¼g©ó¶l¥ó·s»D:uh%[email protected]...
A better link for the offline part:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_da-di_8c32.asp

--

Derek Davis
(e-mail address removed)

If you are using SQL Server...

Take it offline:
http://developer.mimer.com/documentation/html_82/Mimer_SQL_Reference_Manual/SQL_Statements84.html

Restore it:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ra-rz_25rm.asp

--

Derek Davis
(e-mail address removed)

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote in message ad,

There is no way to do this out of the box. If anything, it
depends on the database. Most likely, you will have to use some sort
of administrative interface (there might or might not be one you can
access programatically, depending on the database) to kick everyone
off.

Which database are you using?

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I write a restore program to restore a database.
But it must stop all connecions to the database before resotre.
How can I stop all connecions to the database by program?
 
Back
Top