Showing posts with label appear. Show all posts
Showing posts with label appear. Show all posts

Wednesday, March 28, 2012

How can I clear active connections without disabling the database?

To better explain the question let me build a scenario.
If someone is connected to the database there is an active connection, which does appear in Management Studio. If we try to do a restore of the database, SQL gives us a message saying that it cannot gain exclusive access to the database and the restore fails. To gain exclusive access to the database we need to clear the active connections.
Currently in Management Studio the only ways that I have found to clear the connections are to take the database offline or detach the database completely. What I would like to know is if there is another way to clear the active connections without have to take the database offline or detach it?
In SQL 2000 I could right-click the database, select all tasks, and then select detach database and click clear connections. Of course I would then have to make sure I clicked cancel otherwise I would mistakenly detach the database. This would clear the connections without taking the database offline.
If the only option in Management Studio to clear the connections is to disable the database I would like to request an option under tasks called clear connections. This way the server administrator could click on this to see the current active connections and clear them, either individually, or all of them without having to take the database offline or detach it.
Thanks in advance!

There are several ways you can do this without having to detach the database.
1. run sp_who2 to see all the SPIDs connected to your database. For each SPID, execute kill <spid #>

2. In Object Explorer, Click on Management -> Activity Monitor. RIght-click, select View Processes. From there, you can filter the proccesses any way you want, even by database. After that, you can right-click on each process and select Kill Process.
While it's not a one-shot command, you do have much more control over who gets disconnected.
|||I tried what you suggested and it works. I was curious still though if there are any plans to add a clear connections options that will allow us to clear all connections to a database with one click of a button, similar to SQL 2000.
sql

Wednesday, March 7, 2012

hour separator from . to : ?!?!

In my SQLserver DATA datatype appear to me with hour separator "."
(12.00.00)
I want that they appear with separator ":" (12:00:00) (for to prevent ODBC
problems)
(I have changed the international setting of the server... the OS time is
changed, but in the DB I always have the ".")
Any suggestions?
Is this a dattime datatype? If so it is not stored with any type of
delimiter. Internally it is stored as two Integers and it is up to the
front end to display it however they wish. So if it's displaying with a .
you need to look at your GUI or the driver being used. You can also convert
the datetime to a string with CONVERT() to display it in many different
formats. But as a pure datetime it does not have a display format. See
CONVERT() in BOL for more details.
Andrew J. Kelly SQL MVP
"YURYSSG" <yuryssg@.yahoo.it> wrote in message
news:2qlj83F10pofdU1@.uni-berlin.de...
> In my SQLserver DATA datatype appear to me with hour separator "."
> (12.00.00)
> I want that they appear with separator ":" (12:00:00) (for to prevent
ODBC
> problems)
> (I have changed the international setting of the server... the OS time is
> changed, but in the DB I always have the ".")
> Any suggestions?
> --
>
>
|||If you are using the SQL Server ODBC driver, and you are using the driver to
convert from DATETIME to string (ie. binding the column as SQL_C_CHAR), then
you should be able to change the seperator characters using the Regional
settings on the client machine.
Brannon
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:#B$JQaZmEHA.2020@.TK2MSFTNGP09.phx.gbl...
> Is this a dattime datatype? If so it is not stored with any type of
> delimiter. Internally it is stored as two Integers and it is up to the
> front end to display it however they wish. So if it's displaying with a .
> you need to look at your GUI or the driver being used. You can also
convert[vbcol=seagreen]
> the datetime to a string with CONVERT() to display it in many different
> formats. But as a pure datetime it does not have a display format. See
> CONVERT() in BOL for more details.
> --
> Andrew J. Kelly SQL MVP
>
> "YURYSSG" <yuryssg@.yahoo.it> wrote in message
> news:2qlj83F10pofdU1@.uni-berlin.de...
> ODBC
is
>
|||In the worst case if the above do not work you can always use Replace after
you converted it to string and return it as a string.
"Brannon Jones" <brannonjNOSPAM@.gmail.com> wrote in message
news:OphvrcfmEHA.512@.TK2MSFTNGP10.phx.gbl...
> If you are using the SQL Server ODBC driver, and you are using the driver
> to
> convert from DATETIME to string (ie. binding the column as SQL_C_CHAR),
> then
> you should be able to change the seperator characters using the Regional
> settings on the client machine.
> Brannon
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:#B$JQaZmEHA.2020@.TK2MSFTNGP09.phx.gbl...
> convert
> is
>