显示标签为“disconnect”的博文。显示所有博文
显示标签为“disconnect”的博文。显示所有博文

2012年3月20日星期二

Disconnecting from engine does not closes database

I connect Managment Studio to MSDE 2000SP4.

Open database, open some object, then disconnect from engine (not simple collapse DB objects). In other programm try to drop database. Until you don't close MSSQL MStudio, database is in use.

In older version collapsing DB objects in tree closes DB.

Hi!

I don't have access to MS from 2000SP4, but I can tell you that MS in SQL2005 have Disconnect command in context menu of the server node. I think this is what you need.

|||Does not matter what engine you use. I wrote, that when I DISCONNECT (using this command from menu - this is one way) from engine, database is in use while MS running. So, MS does not disconnect from DB, only delete engine from list.|||Strange, when you Disconnect from server, it must lost connection and must release locks on any DB that was locked.|||

Please, read my first post and try to reproduce it. After disconnecting, try to drop database you used in SSMS. Open new query in SSMS and try. "Cannot drop..."

It's not strange, IT IS A BUG.

|||I have "Drop connections" checkbox for that case. It works in SQL2000 and I see it in SQL2005.|||

Where did you see this checkbox in SSMS?

May be this checkbox exists (I don't find it, but when I DISCONNECT from server all objects incl DB MUST be CLOSED.

I had no this problem in SQL2000 cause database was auto closed after collapsing it's objects in tree and when it wasn't selected in tree.

|||

I have it in window that appears after "Detach" command. Also I remember there was switch "Auto close" in SQL2000 Enterprise Manager (last tab in DB properties).

Perhabs this is MSDE behavior? I run on SQL Server and don't use MSDE for a long time.

|||

I don't need detach database.

Autoclose is a DB property (must NOT overrides by SSMS) and it's "TRUE". And Autoclose have another purpose - it closes DB after all users disconnects.

I had try with Autoclose = True and AC = false. Result: Cannot drop database.

There is no difference between MSSQL and MSDE for such things.

May be you'll try?

|||Please, describe steps to reproduce, I will try it.

disconnecting all users

How can I disconnect all other users from a SQL Server database, except for the one that issues the command
Go to www.dbmaint.com and look for the Utility stored procedures there...
Tibor has a proc that will kill all users connected to a particular
database...You can change it to execlude the spid it runs under, OR simply
move to another db..
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Craig HB" <CraigHB@.discussions.microsoft.com> wrote in message
news:C97A47BF-E76C-4EAD-BA49-41496FB5E104@.microsoft.com...
> How can I disconnect all other users from a SQL Server database, except
for the one that issues the command
|||Try this:
use yourdb
go
alter database yourdb
set single_user with rollback immediate
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Craig HB" <CraigHB@.discussions.microsoft.com> wrote in message
news:C97A47BF-E76C-4EAD-BA49-41496FB5E104@.microsoft.com...
> How can I disconnect all other users from a SQL Server database, except
for the one that issues the command
|||ALTER DATABASE YourDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
USE YourDatabase
GO
... You've now set it to single user mode and then you've become that single
user.
"Craig HB" <CraigHB@.discussions.microsoft.com> wrote in message
news:C97A47BF-E76C-4EAD-BA49-41496FB5E104@.microsoft.com...
> How can I disconnect all other users from a SQL Server database, except
for the one that issues the command
|||those Utility stored procedures are really useful
thanks for letting me know about them
- Craig

disconnecting all users

How can I disconnect all other users from a SQL Server database, except for
the one that issues the commandGo to www.dbmaint.com and look for the Utility stored procedures there...
Tibor has a proc that will kill all users connected to a particular
database...You can change it to execlude the spid it runs under, OR simply
move to another db..
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Craig HB" <CraigHB@.discussions.microsoft.com> wrote in message
news:C97A47BF-E76C-4EAD-BA49-41496FB5E104@.microsoft.com...
> How can I disconnect all other users from a SQL Server database, except
for the one that issues the command|||Try this:
use yourdb
go
alter database yourdb
set single_user with rollback immediate
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Craig HB" <CraigHB@.discussions.microsoft.com> wrote in message
news:C97A47BF-E76C-4EAD-BA49-41496FB5E104@.microsoft.com...
> How can I disconnect all other users from a SQL Server database, except
for the one that issues the command|||ALTER DATABASE YourDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
USE YourDatabase
GO
... You've now set it to single user mode and then you've become that singl
e
user.
"Craig HB" <CraigHB@.discussions.microsoft.com> wrote in message
news:C97A47BF-E76C-4EAD-BA49-41496FB5E104@.microsoft.com...
> How can I disconnect all other users from a SQL Server database, except
for the one that issues the command|||those Utility stored procedures are really useful
thanks for letting me know about them
- Craig

2012年3月19日星期一

Disconnected application and replication

Hi
We have a situation where the sql server backend is on the server but
several laptop users need to disconnect and still be able to use the data.
Can we have copies of say sql express on each laptop which can replicate
data with the sql server when connected and still make the data available
while disconnected from the server? Will this work, specially when the app
front end will be in vb.net?
Thanks
RegardsJohn,
yes - this can work. You'd have a merge publication and pull subscriptions,
activated by your vb.net application.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)|||Or you could have the sync managed by Windows Synchronization Manager or
task scheduler. SQL Server Express does not ship with a scheduler. I would
also have a look at SQL Server Everywhere edition - due out this summer.
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:umptsNFZGHA.4144@.TK2MSFTNGP04.phx.gbl...
> John,
> yes - this can work. You'd have a merge publication and pull
> subscriptions, activated by your vb.net application.
> Cheers,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>|||Ok, but is it the best/recommended way? I mean what do other people do in
this situation?
Thanks
Regards
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:umptsNFZGHA.4144@.TK2MSFTNGP04.phx.gbl...
> John,
> yes - this can work. You'd have a merge publication and pull
> subscriptions, activated by your vb.net application.
> Cheers,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>|||It depends on your requirements. The question is do you want the app to
manage the sync, or do you want it done externally.
If you want the app to manage the sync use the activeX merge control. If you
do not use WSM or task scheduler. WSM has a rich set of functionality for
controlling the sync. If you choose to use task scheduler you will have to
have it instantiate the activeX control to do the sync.
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"John" <John@.nospam.infovis.co.uk> wrote in message
news:uGU3ovHZGHA.4944@.TK2MSFTNGP02.phx.gbl...
> Ok, but is it the best/recommended way? I mean what do other people do in
> this situation?
> Thanks
> Regards
> "Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
> news:umptsNFZGHA.4144@.TK2MSFTNGP04.phx.gbl...
>

Disconnected application and replication

Hi
We have a situation where the sql server backend is on the server but
several laptop users need to disconnect and still be able to use the data.
Can we have copies of say sql express on each laptop which can replicate
data with the sql server when connected and still make the data available
while disconnected from the server? Will this work, specially when the app
front end will be in vb.net?
Thanks
RegardsJohn,
yes - this can work. You'd have a merge publication and pull subscriptions,
activated by your vb.net application.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)|||Or you could have the sync managed by Windows Synchronization Manager or
task scheduler. SQL Server Express does not ship with a scheduler. I would
also have a look at SQL Server Everywhere edition - due out this summer.
--
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:umptsNFZGHA.4144@.TK2MSFTNGP04.phx.gbl...
> John,
> yes - this can work. You'd have a merge publication and pull
> subscriptions, activated by your vb.net application.
> Cheers,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>|||Ok, but is it the best/recommended way? I mean what do other people do in
this situation?
Thanks
Regards
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:umptsNFZGHA.4144@.TK2MSFTNGP04.phx.gbl...
> John,
> yes - this can work. You'd have a merge publication and pull
> subscriptions, activated by your vb.net application.
> Cheers,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>|||It depends on your requirements. The question is do you want the app to
manage the sync, or do you want it done externally.
If you want the app to manage the sync use the activeX merge control. If you
do not use WSM or task scheduler. WSM has a rich set of functionality for
controlling the sync. If you choose to use task scheduler you will have to
have it instantiate the activeX control to do the sync.
--
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"John" <John@.nospam.infovis.co.uk> wrote in message
news:uGU3ovHZGHA.4944@.TK2MSFTNGP02.phx.gbl...
> Ok, but is it the best/recommended way? I mean what do other people do in
> this situation?
> Thanks
> Regards
> "Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
> news:umptsNFZGHA.4144@.TK2MSFTNGP04.phx.gbl...
>> John,
>> yes - this can work. You'd have a merge publication and pull
>> subscriptions, activated by your vb.net application.
>> Cheers,
>> Paul Ibison SQL Server MVP, www.replicationanswers.com
>> (recommended sql server 2000 replication book:
>> http://www.nwsu.com/0974973602p.html)
>

Disconnect/Clear connections

I have a scheduled job where I'm attempting to restore a full backup of our
Production database, over our Test/Dev database.
However, it keeps failing.
When I try to run the Restore Database command manually, I get an error that
states "Exclusive access could not be obtained".
Right now, the only way I know how to clear the connections is to go into
the Detach Database task, and select 'Clear all connections'.
I tried using the 'Exec SQL Disconnect ALL' command, but that statement
won't parse.
Is there another way to clear all database connections? Preferebly in
Trasact-SQL language, that I could schedule to run immediately prior to the
Restore Database command?
Please advise.
Thanks!
YsandreYsandre wrote:
> I have a scheduled job where I'm attempting to restore a full backup of our
> Production database, over our Test/Dev database.
> However, it keeps failing.
> When I try to run the Restore Database command manually, I get an error that
> states "Exclusive access could not be obtained".
> Right now, the only way I know how to clear the connections is to go into
> the Detach Database task, and select 'Clear all connections'.
> I tried using the 'Exec SQL Disconnect ALL' command, but that statement
> won't parse.
> Is there another way to clear all database connections? Preferebly in
> Trasact-SQL language, that I could schedule to run immediately prior to the
> Restore Database command?
> Please advise.
> Thanks!
> Ysandre
Read up on the ALTER DATABASE command
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||I did, but I don't see anything in there regarding clearing connections to
the database.
Is there somewhere else I should look?
All I'm looking for is something along the lines of:
EXEC SQL DISCONNECT ALL
Or why the above doesn't parse.
Thanks!
Ysandre
"Tracy McKibben" wrote:
> Ysandre wrote:
> > I have a scheduled job where I'm attempting to restore a full backup of our
> > Production database, over our Test/Dev database.
> > However, it keeps failing.
> > When I try to run the Restore Database command manually, I get an error that
> > states "Exclusive access could not be obtained".
> > Right now, the only way I know how to clear the connections is to go into
> > the Detach Database task, and select 'Clear all connections'.
> > I tried using the 'Exec SQL Disconnect ALL' command, but that statement
> > won't parse.
> > Is there another way to clear all database connections? Preferebly in
> > Trasact-SQL language, that I could schedule to run immediately prior to the
> > Restore Database command?
> > Please advise.
> > Thanks!
> > Ysandre
> Read up on the ALTER DATABASE command
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com
>|||In short: When you go to Detach/Clear in the EMC to disconnect all the
users it is going to do a couple things.
First - It searches through the sysprocesses for the DB you want to
clear and finds the spid's
Then - set noexec off set parseonly off
Lastly - kill spid#
Hope this helps.
Cheers,
Ysandre wrote:
> I did, but I don't see anything in there regarding clearing connections to
> the database.
> Is there somewhere else I should look?
> All I'm looking for is something along the lines of:
> EXEC SQL DISCONNECT ALL
> Or why the above doesn't parse.
> Thanks!
> Ysandre
> "Tracy McKibben" wrote:
> > Ysandre wrote:
> > > I have a scheduled job where I'm attempting to restore a full backup of our
> > > Production database, over our Test/Dev database.
> > > However, it keeps failing.
> > > When I try to run the Restore Database command manually, I get an error that
> > > states "Exclusive access could not be obtained".
> > > Right now, the only way I know how to clear the connections is to go into
> > > the Detach Database task, and select 'Clear all connections'.
> > > I tried using the 'Exec SQL Disconnect ALL' command, but that statement
> > > won't parse.
> > > Is there another way to clear all database connections? Preferebly in
> > > Trasact-SQL language, that I could schedule to run immediately prior to the
> > > Restore Database command?
> > > Please advise.
> > > Thanks!
> > > Ysandre
> >
> > Read up on the ALTER DATABASE command
> >
> >
> > --
> > Tracy McKibben
> > MCDBA
> > http://www.realsqlguy.com
> >|||You could try something like this. Replace the DBID with the database
you are backing up:
DECLARE SpidsToKill CURSOR FOR
SELECT spid
FROM master..sysprocesses
WHERE dbid = 9
DECLARE @.Spid int
DECLARE @.SQL varchar(255)
OPEN SpidsToKill
FETCH NEXT FROM SpidsToKill
INTO @.Spid
WHILE ( @.@.FETCH_STATUS = 0 )
BEGIN
SELECT @.SQL = 'KILL ' + CONVERT( varchar(10), @.Spid )
EXEC ( @.SQL )
FETCH NEXT FROM SpidsToKill
INTO @.Spid
END
CLOSE SpidsToKill
DEALLOCATE SpidsToKill|||Ysandre wrote:
> I did, but I don't see anything in there regarding clearing connections to
> the database.
You want to use ALTER DATABASE to put the database in SINGLE_USER mode,
WITH immediate ROLLBACK of transactions...
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||That worked.
THANK YOU!!!
"10001110101" wrote:
> You could try something like this. Replace the DBID with the database
> you are backing up:
> DECLARE SpidsToKill CURSOR FOR
> SELECT spid
> FROM master..sysprocesses
> WHERE dbid = 9
> DECLARE @.Spid int
> DECLARE @.SQL varchar(255)
> OPEN SpidsToKill
> FETCH NEXT FROM SpidsToKill
> INTO @.Spid
> WHILE ( @.@.FETCH_STATUS = 0 )
> BEGIN
> SELECT @.SQL = 'KILL ' + CONVERT( varchar(10), @.Spid )
> EXEC ( @.SQL )
> FETCH NEXT FROM SpidsToKill
> INTO @.Spid
> END
> CLOSE SpidsToKill
> DEALLOCATE SpidsToKill
>|||Ysandre wrote:
> That worked.
> THANK YOU!!!
>
Ugh, it's too painful to watch... Drop that cursor nonsense, you can
accomplish this with ONE STATEMENT. Since you can't read documentation
and piece together the command yourself, here it is:
ALTER DATABASE DBName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
That will put the database in single-user mode, allowing one connection
only, and will gracefully rollback any outstanding transactions.
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||This is a multi-part message in MIME format.
--=_NextPart_000_141C_01C6AF0A.34C3D1A0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: quoted-printable
The problem with the script above to 'kill' sessions, is that a session =may immediately reconnect.
The BEST solution, is as Tracy advised. Use
ALTER DATABASE MyDatabase
SET SINGLE_USER WTIH ROLLBACK IMMEDIATE
-- Arnie Rowland
Most good judgment comes from experience. Most experience comes from bad judgment. - Anonymous
"Tracy McKibben" <tracy@.realsqlguy.com> wrote in message =news:%23EmybC0rGHA.1592@.TK2MSFTNGP02.phx.gbl...
> Ysandre wrote:
>> I did, but I don't see anything in there regarding clearing =connections to >> the database.
> > You want to use ALTER DATABASE to put the database in SINGLE_USER =mode, > WITH immediate ROLLBACK of transactions...
> > > -- > Tracy McKibben
> MCDBA
> http://www.realsqlguy.com
--=_NextPart_000_141C_01C6AF0A.34C3D1A0
Content-Type: text/html;
charset="Utf-8"
Content-Transfer-Encoding: quoted-printable
=EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

The problem with the script above to ='kill' sessions, is that a session may immediately reconnect.
The BEST solution, is as Tracy advised. =Use
ALTER DATABASE =MyDatabase
SET SINGLE_USER =WTIH ROLLBACK IMMEDIATE
-- Arnie RowlandMost good =judgment comes from experience. Most experience comes from bad judgment. =- Anonymous
"Tracy McKibben" =wrote in message news:%23EmybC0rGHA.1592@.TK2MSFTNGP02.phx.gbl...> =Ysandre wrote:> I did, but I don't see anything in there regarding =clearing connections to > the database.> > You want to =use ALTER DATABASE to put the database in SINGLE_USER mode, > WITH =immediate ROLLBACK of transactions...> > > -- > Tracy McKibben> MCDBA>">http://www.realsqlguy.com</FONT></A></BODY></HTML>
--=_NextPart_000_141C_01C6AF0A.34C3D1A0--

Disconnect/Clear connections

I have a scheduled job where I'm attempting to restore a full backup of our
Production database, over our Test/Dev database.
However, it keeps failing.
When I try to run the Restore Database command manually, I get an error that
states "Exclusive access could not be obtained".
Right now, the only way I know how to clear the connections is to go into
the Detach Database task, and select 'Clear all connections'.
I tried using the 'Exec SQL Disconnect ALL' command, but that statement
won't parse.
Is there another way to clear all database connections? Preferebly in
Trasact-SQL language, that I could schedule to run immediately prior to the
Restore Database command?
Please advise.
Thanks!
YsandreYsandre wrote:
> I have a scheduled job where I'm attempting to restore a full backup of ou
r
> Production database, over our Test/Dev database.
> However, it keeps failing.
> When I try to run the Restore Database command manually, I get an error th
at
> states "Exclusive access could not be obtained".
> Right now, the only way I know how to clear the connections is to go into
> the Detach Database task, and select 'Clear all connections'.
> I tried using the 'Exec SQL Disconnect ALL' command, but that statement
> won't parse.
> Is there another way to clear all database connections? Preferebly in
> Trasact-SQL language, that I could schedule to run immediately prior to th
e
> Restore Database command?
> Please advise.
> Thanks!
> Ysandre
Read up on the ALTER DATABASE command
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||I did, but I don't see anything in there regarding clearing connections to
the database.
Is there somewhere else I should look?
All I'm looking for is something along the lines of:
EXEC SQL DISCONNECT ALL
Or why the above doesn't parse.
Thanks!
Ysandre
"Tracy McKibben" wrote:

> Ysandre wrote:
> Read up on the ALTER DATABASE command
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com
>|||In short: When you go to Detach/Clear in the EMC to disconnect all the
users it is going to do a couple things.
First - It searches through the sysprocesses for the DB you want to
clear and finds the spid's
Then - set noexec off set parseonly off
Lastly - kill spid#
Hope this helps.
Cheers,
Ysandre wrote:[vbcol=seagreen]
> I did, but I don't see anything in there regarding clearing connections to
> the database.
> Is there somewhere else I should look?
> All I'm looking for is something along the lines of:
> EXEC SQL DISCONNECT ALL
> Or why the above doesn't parse.
> Thanks!
> Ysandre
> "Tracy McKibben" wrote:
>|||You could try something like this. Replace the DBID with the database
you are backing up:
DECLARE SpidsToKill CURSOR FOR
SELECT spid
FROM master..sysprocesses
WHERE dbid = 9
DECLARE @.Spid int
DECLARE @.SQL varchar(255)
OPEN SpidsToKill
FETCH NEXT FROM SpidsToKill
INTO @.Spid
WHILE ( @.@.FETCH_STATUS = 0 )
BEGIN
SELECT @.SQL = 'KILL ' + CONVERT( varchar(10), @.Spid )
EXEC ( @.SQL )
FETCH NEXT FROM SpidsToKill
INTO @.Spid
END
CLOSE SpidsToKill
DEALLOCATE SpidsToKill|||Ysandre wrote:
> I did, but I don't see anything in there regarding clearing connections to
> the database.
You want to use ALTER DATABASE to put the database in SINGLE_USER mode,
WITH immediate ROLLBACK of transactions...
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||That worked.
THANK YOU!!!
"10001110101" wrote:

> You could try something like this. Replace the DBID with the database
> you are backing up:
> DECLARE SpidsToKill CURSOR FOR
> SELECT spid
> FROM master..sysprocesses
> WHERE dbid = 9
> DECLARE @.Spid int
> DECLARE @.SQL varchar(255)
> OPEN SpidsToKill
> FETCH NEXT FROM SpidsToKill
> INTO @.Spid
> WHILE ( @.@.FETCH_STATUS = 0 )
> BEGIN
> SELECT @.SQL = 'KILL ' + CONVERT( varchar(10), @.Spid )
> EXEC ( @.SQL )
> FETCH NEXT FROM SpidsToKill
> INTO @.Spid
> END
> CLOSE SpidsToKill
> DEALLOCATE SpidsToKill
>|||Ysandre wrote:
> That worked.
> THANK YOU!!!
>
Ugh, it's too painful to watch... Drop that cursor nonsense, you can
accomplish this with ONE STATEMENT. Since you can't read documentation
and piece together the command yourself, here it is:
ALTER DATABASE DBName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
That will put the database in single-user mode, allowing one connection
only, and will gracefully rollback any outstanding transactions.
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||The problem with the script above to 'kill' sessions, is that a session may
immediately reconnect.
The BEST solution, is as Tracy advised. Use
ALTER DATABASE MyDatabase
SET SINGLE_USER WTIH ROLLBACK IMMEDIATE
--
Arnie Rowland
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Tracy McKibben" <tracy@.realsqlguy.com> wrote in message news:%23EmybC0rGHA.1592@.TK2MSFTNGP0
2.phx.gbl...
> Ysandre wrote:
>
> You want to use ALTER DATABASE to put the database in SINGLE_USER mode,
> WITH immediate ROLLBACK of transactions...
>
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com

disconnect users from a database

I need to be able to drop all user from one database in script...can someon
e point me in the right direction or if its really simple, tell me how?you have to select the spid 's from sysprocesses table that related to db yo
u want and then run kill (spid) command for that spid's.
I think there are some sample scripts to do that on the web like www.databasejorna
l.com etc..
"Jamie Elliott" wrote:

> I need to be able to drop all user from one database in script...can someone poin
t me in the right direction or if its really simple, tell me how?|||Hi,
Did you meant to drop the users or disconnect all users from database.
Disconnenct all users in a database:-
alter database <dbname> set single_user with rollback immediate
Drop the users:-
sp_dropuser <user_name>
You could write a script based on sysusers table.
select 'sp_dropuser ' +name +char(10)+'go' from sysusers where uid>4
Execute the below script with text result and copy the result and paste in a
new window to drop all users apart from system created users.
The drop user will fail if the user owns any object. In that case you have
to change the object owner using sp_changeobjectowner system procedure
(See books online)
Thanks
Hari
MCDBA
"Jamie Elliott" <JamieElliott@.discussions.microsoft.com> wrote in message
news:126F63B8-31B4-4F21-9903-6489C4F862F3@.microsoft.com...
> I need to be able to drop all user from one database in script...can
someone point me in the right direction or if its really simple, tell me
how?

disconnect users from a database

I need to be able to drop all user from one database in script...can someone point me in the right direction or if its really simple, tell me how?
you have to select the spid 's from sysprocesses table that related to db you want and then run kill (spid) command for that spid's.
I think there are some sample scripts to do that on the web like www.databasejornal.com etc..
"Jamie Elliott" wrote:

> I need to be able to drop all user from one database in script...can someone point me in the right direction or if its really simple, tell me how?
|||Hi,
Did you meant to drop the users or disconnect all users from database.
Disconnenct all users in a database:-
alter database <dbname> set single_user with rollback immediate
Drop the users:-
sp_dropuser <user_name>
You could write a script based on sysusers table.
select 'sp_dropuser ' +name +char(10)+'go' from sysusers where uid>4
Execute the below script with text result and copy the result and paste in a
new window to drop all users apart from system created users.
The drop user will fail if the user owns any object. In that case you have
to change the object owner using sp_changeobjectowner system procedure
(See books online)
Thanks
Hari
MCDBA
"Jamie Elliott" <JamieElliott@.discussions.microsoft.com> wrote in message
news:126F63B8-31B4-4F21-9903-6489C4F862F3@.microsoft.com...
> I need to be able to drop all user from one database in script...can
someone point me in the right direction or if its really simple, tell me
how?

disconnect users

Hi,
I was wondering if there is a stored procedure that could disconnect users.
I have job which does some integrity checks, but for one database it
always fails. There is always a connection open. That particular
useraccount is for the oracle applicationserver which should remain active.
How can i resolve this matter and still do maintenance?Do you want to disconnect the users, or not disconnect that user?
If you want to disconnect the users:
USE <databasename>
GO
ALTER DATABASE <databasename> SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
(note, this will force all users out and cause any transactions they're in
to roll back -- immediately. There is also a time option; look up syntax in
BOL.)
To allow other users to connect once you're done:
ALTER DATABASE <databasename> SET MULTI_USER
GO
Adam Machanic
Pro SQL Server 2005, available now
http://www.apress.com/book/bookDisplay.html?bID=457
--
"Jason" <jasonlewis@.hotmail.com> wrote in message
news:%23Qqt7rkeGHA.4912@.TK2MSFTNGP05.phx.gbl...
> Hi,
> I was wondering if there is a stored procedure that could disconnect
> users.
> I have job which does some integrity checks, but for one database it
> always fails. There is always a connection open. That particular
> useraccount is for the oracle applicationserver which should remain
> active.
> How can i resolve this matter and still do maintenance?

disconnect users

Hi,
I was wondering if there is a stored procedure that could disconnect users.
I have job which does some integrity checks, but for one database it
always fails. There is always a connection open. That particular
useraccount is for the oracle applicationserver which should remain active.
How can i resolve this matter and still do maintenance?Do you want to disconnect the users, or not disconnect that user?
If you want to disconnect the users:
USE <databasename>
GO
ALTER DATABASE <databasename> SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
(note, this will force all users out and cause any transactions they're in
to roll back -- immediately. There is also a time option; look up syntax in
BOL.)
To allow other users to connect once you're done:
ALTER DATABASE <databasename> SET MULTI_USER
GO
Adam Machanic
Pro SQL Server 2005, available now
http://www.apress.com/book/bookDisplay.html?bID=457
--
"Jason" <jasonlewis@.hotmail.com> wrote in message
news:%23Qqt7rkeGHA.4912@.TK2MSFTNGP05.phx.gbl...
> Hi,
> I was wondering if there is a stored procedure that could disconnect
> users.
> I have job which does some integrity checks, but for one database it
> always fails. There is always a connection open. That particular
> useraccount is for the oracle applicationserver which should remain
> active.
> How can i resolve this matter and still do maintenance?

disconnect the user

I'm trying to detach my database.But i couldn't do that coz there are some users connected to it. So how can i disconnect them?is there any way to disconnect them from the DB?
Thanks.In SQL server 2000

When you detach a database it should give you an option to kill all user processes, if you click that it will log off all users.

If not I have some t-sql code that does it.|||It worked fine.Thank you very much.

Disconnect Issues & RPC Server Unavailable

We have recently upgraded our main server from NT4 to Active Directory
(Windows 2003 Server). Our SQL Database is 2000 and is running on a Windows
2000 Server Box. We use com+ components to connect to our database. Since
the change on our PDC to 2003 Server AD, we have had several errors such as
"The object invoked has disconnected from its clients" as well as RPC Server
Unavailable. This occurs even when the user is consistently active. We have
applied latest Windows Service Pack to clients xp sp2 and to the windows 2000
server box. If you reboot the server and or/stop services (Com+ and Dcom) on
the client end, they can get back in. You can browse to the machine no
problem through exporer - right to the database. Issue is only in SQL 2000.
Any assistance would be greatly appreciated. Note: I have also checked
using netstat -a to see if all ports were being used and that is not the
case. This is happening on more than one users connection and I am certain
it is not network based - ping 100%, can browse, two locations within
building etc.
We had a similar problem after upgrading clients to XP SP2, the problem
turned out to be the MDAC version that ships with SP2. Apparently, the new
version of MDAC has issues keeping a connection with the DB if it is using
named pipes. An example of this is when we would run a restore with QA using
the normal connection to a server(named pipes) it would die and say
something about a disconnect even though ping is at 100%. As soon as we
forced tcp/ip on QA everything worked fine. Might try setting up an alias to
the server using tcp/ip to see if that makes a difference.
KevinE
"Cstewart" <Cstewart@.discussions.microsoft.com> wrote in message
news:7FEEA68E-6785-480B-9F97-C81C7BD0ACD1@.microsoft.com...
> We have recently upgraded our main server from NT4 to Active Directory
> (Windows 2003 Server). Our SQL Database is 2000 and is running on a
> Windows
> 2000 Server Box. We use com+ components to connect to our database.
> Since
> the change on our PDC to 2003 Server AD, we have had several errors such
> as
> "The object invoked has disconnected from its clients" as well as RPC
> Server
> Unavailable. This occurs even when the user is consistently active. We
> have
> applied latest Windows Service Pack to clients xp sp2 and to the windows
> 2000
> server box. If you reboot the server and or/stop services (Com+ and Dcom)
> on
> the client end, they can get back in. You can browse to the machine no
> problem through exporer - right to the database. Issue is only in SQL
> 2000.
> Any assistance would be greatly appreciated. Note: I have also checked
> using netstat -a to see if all ports were being used and that is not the
> case. This is happening on more than one users connection and I am
> certain
> it is not network based - ping 100%, can browse, two locations within
> building etc.
|||The issue is regardless of sp1 or 2. Any error logs you can suggest for me
to look at?
Thank you
"KevinE" wrote:

> We had a similar problem after upgrading clients to XP SP2, the problem
> turned out to be the MDAC version that ships with SP2. Apparently, the new
> version of MDAC has issues keeping a connection with the DB if it is using
> named pipes. An example of this is when we would run a restore with QA using
> the normal connection to a server(named pipes) it would die and say
> something about a disconnect even though ping is at 100%. As soon as we
> forced tcp/ip on QA everything worked fine. Might try setting up an alias to
> the server using tcp/ip to see if that makes a difference.
> KevinE
> "Cstewart" <Cstewart@.discussions.microsoft.com> wrote in message
> news:7FEEA68E-6785-480B-9F97-C81C7BD0ACD1@.microsoft.com...
>
>

disconnect in an emergency

Hi,
In the event of an emergency restore in SQL 2000, I used to right
click on a database, choose detach and then the "clear" button to
disconnect all users. I didn't actually detach the database, this just
was my sneak out to disconnect so I could run my restore scripts for
the db backups and the logs. I do have a script that I can run that
loops through the SP_WHO results and kills all the spids, but that
takes time and I don't want to have to build that into my restore
scripts.
Does anyone know of a quick way in SSMS where I can detach users from
a database? There are so many more options, I am wondering if I am
just missing where to click?
Thanks all you gurus out there.
KristinaAlter Database Foo set offline with rollback immediate
Go
alter database foo set online
Go
Geoff N. Hiten
Senior Database Administrator
Microsoft SQL Server MVP
"Kristina" <KristinaDBA@.gmail.com> wrote in message
news:1181324410.567760.132940@.k79g2000hse.googlegroups.com...
> Hi,
> In the event of an emergency restore in SQL 2000, I used to right
> click on a database, choose detach and then the "clear" button to
> disconnect all users. I didn't actually detach the database, this just
> was my sneak out to disconnect so I could run my restore scripts for
> the db backups and the logs. I do have a script that I can run that
> loops through the SP_WHO results and kills all the spids, but that
> takes time and I don't want to have to build that into my restore
> scripts.
> Does anyone know of a quick way in SSMS where I can detach users from
> a database? There are so many more options, I am wondering if I am
> just missing where to click?
> Thanks all you gurus out there.
> Kristina
>|||On Jun 8, 1:48 pm, "Geoff N. Hiten" <SQLCrafts...@.gmail.com> wrote:
> Alter Database Foo set offline with rollback immediate
> Go
> alter database foo set online
> Go
> --
> Geoff N. Hiten
> Senior Database Administrator
> Microsoft SQL Server MVP
> "Kristina" <Kristina...@.gmail.com> wrote in message
> news:1181324410.567760.132940@.k79g2000hse.googlegroups.com...
>
> > Hi,
> > In the event of an emergency restore in SQL 2000, I used to right
> > click on a database, choose detach and then the "clear" button to
> > disconnect all users. I didn't actually detach the database, this just
> > was my sneak out to disconnect so I could run my restore scripts for
> > the db backups and the logs. I do have a script that I can run that
> > loops through the SP_WHO results and kills all the spids, but that
> > takes time and I don't want to have to build that into my restore
> > scripts.
> > Does anyone know of a quick way in SSMS where I can detach users from
> > a database? There are so many more options, I am wondering if I am
> > just missing where to click?
> > Thanks all you gurus out there.
> > Kristina- Hide quoted text -
> - Show quoted text -
THANKS! I actually did this, but omitted the rollback immediate.
perfect! :)

disconnect in an emergency

Hi,
In the event of an emergency restore in SQL 2000, I used to right
click on a database, choose detach and then the "clear" button to
disconnect all users. I didn't actually detach the database, this just
was my sneak out to disconnect so I could run my restore scripts for
the db backups and the logs. I do have a script that I can run that
loops through the SP_WHO results and kills all the spids, but that
takes time and I don't want to have to build that into my restore
scripts.
Does anyone know of a quick way in SSMS where I can detach users from
a database? There are so many more options, I am wondering if I am
just missing where to click?
Thanks all you gurus out there.
KristinaAlter Database Foo set offline with rollback immediate
Go
alter database foo set online
Go
Geoff N. Hiten
Senior Database Administrator
Microsoft SQL Server MVP
"Kristina" <KristinaDBA@.gmail.com> wrote in message
news:1181324410.567760.132940@.k79g2000hse.googlegroups.com...
> Hi,
> In the event of an emergency restore in SQL 2000, I used to right
> click on a database, choose detach and then the "clear" button to
> disconnect all users. I didn't actually detach the database, this just
> was my sneak out to disconnect so I could run my restore scripts for
> the db backups and the logs. I do have a script that I can run that
> loops through the SP_WHO results and kills all the spids, but that
> takes time and I don't want to have to build that into my restore
> scripts.
> Does anyone know of a quick way in SSMS where I can detach users from
> a database? There are so many more options, I am wondering if I am
> just missing where to click?
> Thanks all you gurus out there.
> Kristina
>|||On Jun 8, 1:48 pm, "Geoff N. Hiten" <SQLCrafts...@.gmail.com> wrote:
> Alter Database Foo set offline with rollback immediate
> Go
> alter database foo set online
> Go
> --
> Geoff N. Hiten
> Senior Database Administrator
> Microsoft SQL Server MVP
> "Kristina" <Kristina...@.gmail.com> wrote in message
> news:1181324410.567760.132940@.k79g2000hse.googlegroups.com...
>
>
>
>
>
>
> - Show quoted text -
THANKS! I actually did this, but omitted the rollback immediate.
perfect!

disconnect in an emergency

Hi,
In the event of an emergency restore in SQL 2000, I used to right
click on a database, choose detach and then the "clear" button to
disconnect all users. I didn't actually detach the database, this just
was my sneak out to disconnect so I could run my restore scripts for
the db backups and the logs. I do have a script that I can run that
loops through the SP_WHO results and kills all the spids, but that
takes time and I don't want to have to build that into my restore
scripts.
Does anyone know of a quick way in SSMS where I can detach users from
a database? There are so many more options, I am wondering if I am
just missing where to click?
Thanks all you gurus out there.
Kristina
Alter Database Foo set offline with rollback immediate
Go
alter database foo set online
Go
Geoff N. Hiten
Senior Database Administrator
Microsoft SQL Server MVP
"Kristina" <KristinaDBA@.gmail.com> wrote in message
news:1181324410.567760.132940@.k79g2000hse.googlegr oups.com...
> Hi,
> In the event of an emergency restore in SQL 2000, I used to right
> click on a database, choose detach and then the "clear" button to
> disconnect all users. I didn't actually detach the database, this just
> was my sneak out to disconnect so I could run my restore scripts for
> the db backups and the logs. I do have a script that I can run that
> loops through the SP_WHO results and kills all the spids, but that
> takes time and I don't want to have to build that into my restore
> scripts.
> Does anyone know of a quick way in SSMS where I can detach users from
> a database? There are so many more options, I am wondering if I am
> just missing where to click?
> Thanks all you gurus out there.
> Kristina
>
|||On Jun 8, 1:48 pm, "Geoff N. Hiten" <SQLCrafts...@.gmail.com> wrote:
> Alter Database Foo set offline with rollback immediate
> Go
> alter database foo set online
> Go
> --
> Geoff N. Hiten
> Senior Database Administrator
> Microsoft SQL Server MVP
> "Kristina" <Kristina...@.gmail.com> wrote in message
> news:1181324410.567760.132940@.k79g2000hse.googlegr oups.com...
>
>
>
>
> - Show quoted text -
THANKS! I actually did this, but omitted the rollback immediate.
perfect!

Disconnect from sql server database

Hi
I have c# application that uses SQL SERVER databases.
The problem is that after I close all connections to a database in order to
make actions (detach, copy or delete) on the current database I get a
message saying that the database still has connections.
At the Enterprise manager I can see that the current database still has 2
connections although I closed them in my application.
I would like to disconnect from the database through the application and
make the actions that were mentioned above, how can I do that?
Thanks,
Eyal
On SQL SERVER 2000, you can disconnect all the current connections with:
ALTER DATABASE your_database SET SINGLE_USER WITH ROLLBACK IMMEDIATE
USE master
DROP DATABASE your_database etc..
You need USE master, otherwise you're still connected yourself.
Jacco Schalkwijk
SQL Server MVP
"Eyal" <eg@.margan.com> wrote in message
news:eYltEA3BFHA.3592@.TK2MSFTNGP09.phx.gbl...
> Hi
>
> I have c# application that uses SQL SERVER databases.
> The problem is that after I close all connections to a database in order
> to
> make actions (detach, copy or delete) on the current database I get a
> message saying that the database still has connections.
>
> At the Enterprise manager I can see that the current database still has 2
> connections although I closed them in my application.
>
> I would like to disconnect from the database through the application and
> make the actions that were mentioned above, how can I do that?
>
> Thanks,
> Eyal
>

Disconnect from sql server database

Hi
I have c# application that uses SQL SERVER databases.
The problem is that after I close all connections to a database in order to
make actions (detach, copy or delete) on the current database I get a
message saying that the database still has connections.
At the Enterprise manager I can see that the current database still has 2
connections although I closed them in my application.
I would like to disconnect from the database through the application and
make the actions that were mentioned above, how can I do that?
Thanks,
Eyal
My guess is that you are using connection pooling. This is the default
setting for SqlClient. Do please check about connection pooling in .Net
documentation if this is your problem.
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
"Eyal" <eg@.margan.com> wrote in message
news:eAAkq$2BFHA.3236@.TK2MSFTNGP15.phx.gbl...
> Hi
>
> I have c# application that uses SQL SERVER databases.
> The problem is that after I close all connections to a database in order
to
> make actions (detach, copy or delete) on the current database I get a
> message saying that the database still has connections.
>
> At the Enterprise manager I can see that the current database still has 2
> connections although I closed them in my application.
>
> I would like to disconnect from the database through the application and
> make the actions that were mentioned above, how can I do that?
>
> Thanks,
> Eyal
>

Disconnect from sql server database

Hi
I have c# application that uses SQL SERVER databases.
The problem is that after I close all connections to a database in order to
make actions (detach, copy or delete) on the current database I get a
message saying that the database still has connections.
At the Enterprise manager I can see that the current database still has 2
connections although I closed them in my application.
I would like to disconnect from the database through the application and
make the actions that were mentioned above, how can I do that?
Thanks,
EyalMy guess is that you are using connection pooling. This is the default
setting for SqlClient. Do please check about connection pooling in .Net
documentation if this is your problem.
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
"Eyal" <eg@.margan.com> wrote in message
news:eAAkq$2BFHA.3236@.TK2MSFTNGP15.phx.gbl...
> Hi
>
> I have c# application that uses SQL SERVER databases.
> The problem is that after I close all connections to a database in order
to
> make actions (detach, copy or delete) on the current database I get a
> message saying that the database still has connections.
>
> At the Enterprise manager I can see that the current database still has 2
> connections although I closed them in my application.
>
> I would like to disconnect from the database through the application and
> make the actions that were mentioned above, how can I do that?
>
> Thanks,
> Eyal
>

Disconnect error while running re-indexing job.

Hi,
I have a 24Gb database with half a dozen indexes against various
tables which is failing during the reindexing task (as part of the
maintenance plan) at least 80% of the time.
The error given in the logs is:
"[Microsoft SQL-DMO (ODBC SQLState: 01000)] Error 0: This server has
been disconnected. You must reconnect to perform this operation."
Now, I am aware that this means the server disconnected or became
unavailable during the re-indexing, but I cannot find any logical
reason why this should happen. There are no access violations, either
in the SQL logs or the event viewer. No-one manually stopped SQL
Server. No other part of the maintenance plan has any issues. There
are no other errors around the time of this failure.
If anyone has any suggestions as to why this might be occurring, I'd
be grateful to hear them.
Thanks in advance,
Andy.
One of the things I would check is the autogrow/autoshrink options... If
those options are enabled AND your database picks an inopportune time to
grow (or shrink) errors like that are possible.
Steve
"Andy D." <clotho42@.yahoo.com> wrote in message
news:279509a6.0404260826.2b769d01@.posting.google.c om...
> Hi,
> I have a 24Gb database with half a dozen indexes against various
> tables which is failing during the reindexing task (as part of the
> maintenance plan) at least 80% of the time.
> The error given in the logs is:
> "[Microsoft SQL-DMO (ODBC SQLState: 01000)] Error 0: This server has
> been disconnected. You must reconnect to perform this operation."
> Now, I am aware that this means the server disconnected or became
> unavailable during the re-indexing, but I cannot find any logical
> reason why this should happen. There are no access violations, either
> in the SQL logs or the event viewer. No-one manually stopped SQL
> Server. No other part of the maintenance plan has any issues. There
> are no other errors around the time of this failure.
> If anyone has any suggestions as to why this might be occurring, I'd
> be grateful to hear them.
> Thanks in advance,
> Andy.