Showing posts with label connected. Show all posts
Showing posts with label connected. Show all posts

Sunday, March 11, 2012

Check current database

I was wondering if it was possible to check what server database you are currently connected to, using T-SQL, when executing commands in Query Analyzer. Even though you choose the server and database when connection, sometimes by habit you may connect to the wrong server & DB, and execute an .SQL file. Is it possible to put a line of T-SQL at the beginning that performs this pseudo-code, as a safety feature:

-- While in Query Analyzer with a certain .SQL file open:
If current server <> 'TheCorrectServer' and current DB <> 'TheCorrectDB' then cancel this .SQL file execution.Hi there

In Query analyzer type the following to get server name

select @.@.servername

Unsure how to get database name, you could just always put;

use <databasename>

in your code, that way you would always be on the right database|||SELECT db_name()

returns the currently active database|||Thanks a lot! That will help.

Wednesday, March 7, 2012

Check active SQL server 2000 users/connections

How can I check how many users are connected to my SQL 2000 db. Monitor how
many users are active on the database.
regards
simonOn Jul 4, 1:20 pm, Simon79 <Simo...@.discussions.microsoft.com> wrote:
> How can I check how many users are connected to my SQL 2000 db. Monitor ho
w
> many users are active on the database.
> regards
> simon
To check connected sessions
select * from master..sysprocesses where spid > 50
You can check
select spid, datediff(minute,last_batch ,getdate()) from
master..sysprocesses where spid > 50
for how many minutes the session was idle|||Pls try sp_who2 'active'
HTH,
Paul Ibison|||Hi
sp_who 'active'
"Simon79" <Simon79@.discussions.microsoft.com> wrote in message
news:E3126647-65E7-4CDA-B6C8-D4AC4505E165@.microsoft.com...
> How can I check how many users are connected to my SQL 2000 db. Monitor
> how
> many users are active on the database.
> regards
> simon|||Thanx, all your solutions worked great!

Check active SQL server 2000 users/connections

How can I check how many users are connected to my SQL 2000 db. Monitor how
many users are active on the database.
regards
simon
On Jul 4, 1:20 pm, Simon79 <Simo...@.discussions.microsoft.com> wrote:
> How can I check how many users are connected to my SQL 2000 db. Monitor how
> many users are active on the database.
> regards
> simon
To check connected sessions
select * from master..sysprocesses where spid > 50
You can check
select spid, datediff(minute,last_batch ,getdate()) from
master..sysprocesses where spid > 50
for how many minutes the session was idle
|||Pls try sp_who2 'active'
HTH,
Paul Ibison
|||Hi
sp_who 'active'
"Simon79" <Simon79@.discussions.microsoft.com> wrote in message
news:E3126647-65E7-4CDA-B6C8-D4AC4505E165@.microsoft.com...
> How can I check how many users are connected to my SQL 2000 db. Monitor
> how
> many users are active on the database.
> regards
> simon
|||Thanx, all your solutions worked great!

Check active SQL server 2000 users/connections

How can I check how many users are connected to my SQL 2000 db. Monitor how
many users are active on the database.
regards
simonOn Jul 4, 1:20 pm, Simon79 <Simo...@.discussions.microsoft.com> wrote:
> How can I check how many users are connected to my SQL 2000 db. Monitor how
> many users are active on the database.
> regards
> simon
To check connected sessions
select * from master..sysprocesses where spid > 50
You can check
select spid, datediff(minute,last_batch ,getdate()) from
master..sysprocesses where spid > 50
for how many minutes the session was idle|||Pls try sp_who2 'active'
HTH,
Paul Ibison|||Hi
sp_who 'active'
"Simon79" <Simon79@.discussions.microsoft.com> wrote in message
news:E3126647-65E7-4CDA-B6C8-D4AC4505E165@.microsoft.com...
> How can I check how many users are connected to my SQL 2000 db. Monitor
> how
> many users are active on the database.
> regards
> simon|||Thanx, all your solutions worked great!

Check a user is connected to the database or not

Can any one tell me the way to know whether a given user id is
logged into the sql server or connected to any database or not? I want to
remove a user if he is not logged into the server or not connected to any
database.
Can any one give me the T-Sql statement which solves my problem?
Thanks in advance.
VenkatEXEC sp_who 'LoginName' '
Francesco Anti
"Venkat" <tammana@.inooga.com> wrote in message
news:O72%23AandFHA.612@.TK2MSFTNGP12.phx.gbl...
> Can any one tell me the way to know whether a given user id is
> logged into the sql server or connected to any database or not? I want to
> remove a user if he is not logged into the server or not connected to any
> database.
>
> Can any one give me the T-Sql statement which solves my
> problem?
>
> Thanks in advance.
>
> --
> Venkat
>
>|||Hi,
You can use SP_WHO and sp_dropuser and sp_droplogin system stored
procedures.
Thanks
Hari
SQL Server MVP
"Venkat" <tammana@.inooga.com> wrote in message
news:O72%23AandFHA.612@.TK2MSFTNGP12.phx.gbl...
> Can any one tell me the way to know whether a given user id is
> logged into the sql server or connected to any database or not? I want to
> remove a user if he is not logged into the server or not connected to any
> database.
>
> Can any one give me the T-Sql statement which solves my
> problem?
>
> Thanks in advance.
>
> --
> Venkat
>
>