How to remove session by database name

Hi , 
using exec sp_who will show the list of all the sessions.
How i can remove all the session listed by sp_who by database name like master , etc
Thank You , Shan Ali Khan

This is a simple sp_who I named sp_who3  extrapolated by a 2008R2 instance, but you need to make your own and put to master.
alter procedure sp_who3 (--- 1995/11/28 15:48
@dbname varchar(max) = null ,
@loginame sysname = NULL --or 'active'
as
declare @spidlow int,
@spidhigh int,
@spid int,
@sid varbinary(85)
select @spidlow = 0
,@spidhigh = 32767
if ( @loginame is not NULL
AND upper(@loginame collate Latin1_General_CI_AS) = 'ACTIVE'
begin
select spid , ecid, status
,loginame=rtrim(loginame)
,hostname ,blk=convert(char(5),blocked)
,dbname = case
when dbid = 0 then null
when dbid <> 0 then db_name(dbid)
end
,cmd
,request_id
from sys.sysprocesses
where spid >= @spidlow and spid <= @spidhigh AND
upper(cmd) <> 'AWAITING COMMAND'
and ((case
when dbid = 0 then null
when dbid <> 0 then db_name(dbid)
end = @dbname) or (@dbname is null))
return (0)
end
if (@loginame is not NULL
AND upper(@loginame collate Latin1_General_CI_AS) <> 'ACTIVE'
begin
if (@loginame like '[0-9]%') -- is a spid.
begin
select @spid = convert(int, @loginame)
select spid, ecid, status,
loginame=rtrim(loginame),
hostname,blk = convert(char(5),blocked),
dbname = case
when dbid = 0 then null
when dbid <> 0 then db_name(dbid)
end
,cmd
,request_id
from sys.sysprocesses
where spid = @spid and
((case
when dbid = 0 then null
when dbid <> 0 then db_name(dbid)
end) = @dbname or (@dbname is null))
end
else
begin
select @sid = suser_sid(@loginame)
if (@sid is null)
begin
raiserror(15007,-1,-1,@loginame)
return (1)
end
select spid, ecid, status,
loginame=rtrim(loginame),
hostname ,blk=convert(char(5),blocked),
dbname = case
when dbid = 0 then null
when dbid <> 0 then db_name(dbid)
end
,cmd
,request_id
from sys.sysprocesses
where sid = @sid and
(( case
when dbid = 0 then null
when dbid <> 0 then db_name(dbid)
end) = @dbname or (@dbname is null))
end
return (0)
end
-- loginame arg is null
select spid,
ecid,
status,
loginame=rtrim(loginame),
hostname,
blk=convert(char(5),blocked),
dbname = case
when dbid = 0 then null
when dbid <> 0 then db_name(dbid)
end
,cmd
,request_id
from sys.sysprocesses
where spid >= @spidlow and spid <= @spidhigh and
(( case
when dbid = 0 then null
when dbid <> 0 then db_name(dbid)
end) = @dbname or (@dbname is null))
return (0) -- sp_who

Similar Messages

  • How to remove logical standby database configuration cleanly

    Hello,
    We are on RHL with 11.2.0.3 DB version. Due to various unknown reasons we would like to recreate logical standby database and for that purpose I would like to cleanly remove/uninstall/drop LOGICAL STANDBY DATABASE from the DATA GUARD configuration we have.
    The DG setup already has 1 PHYSICAL STANDBY DATABASE which is working fine. PRIM,PHYSICAL, and LOGICAL all are on different HOSTS. Could you please guide or suggest us exact MOS Doc id regarding this? I have found one MOS Doc id which is close enough but its steps include removing dg configuration completely which I don't want. Only Logical Standby database needs to be remove cleanly so that it can be installed again properly.
    We are using GRID CONTROL and DATA GUARD BROKER.
    Bundle of thanks in advance.
    Best Regards

    Hello;
    I would review this Oracle note:
    How to remove a Data Guard Configuration from Primary Database (Doc ID 733794.1)
    Best Regards
    mseberg

  • How can i change the database name on MaxDB?

    Hello.  I need to do a homogeneous copy where the source system is the productive system and the target system is the quality system. Therefore after to restore the data backup i need to change the database name of quality system (from CLP to CLQ) but i'm not sure that it could be possible because in the MaxDB documentation i didn't found nothing about that. please can you tell me if it is possible and how i change it?
    I work with MaxDB 7.6.04.11.  Thanks for your help.

    > I will try to explain better: the SID of the source database is CLP and the SID of the target database is CLQ, when you say "once you restore the DB, it will use the new SID", i understand that the new SID in the target database would CLP or am i wrong? and i need that the SID in the target database remains CLQ after the restore.
    Hi Ivonne,
    what you've described as your requirement is exactly what will happen, when you just perform the procedure that Eric described to you.
    A recovery won't change the SID of the instance you perform the recovery to.
    All it does is: take the instance as is and load the data pages to the data area. Afterwards the log files may be recovered.
    Think of the instance as a kind of container for your database.
    The instance itself is not the database - so the SID does not change with the content of the database.
    Hmm... why not simply try it?
    Create a little test instance and back it up.
    Create another instance with a different name and recover the backup of the first instance.
    You will still have both instances, each with its original name.
    regards,
    Lars

  • How to remove a RAC database

    Hi Guys,
    We have some issues with ASM diskgroups and due to this the diskgroups holding a 2 node RAC DB are not mounted . We want to remove this database cleanly so that we can drop the troubled diskgroups and create new one.Unfortunately we dont have a backup of this database as it is not production.So how can we clean it from asm/crs - dbca needs the database to be up before it can be removed but becuase of asm issue and non-availability of backups,it can not be brought up!
    Any suggestions would be appreciated.
    Thanks.

    Hi,
    as database is mounted by RAC
    1. shutdown node2 (database and ASM instance)
    2. login to node1 , rman- drop database, which will drop all datafile, controlfile etc.
    3. srvclt remove datase -d <db_name> : to remove from CRS reposioty
    4. delete all parameter file or password file etc from $ORALCE_HOME/dbs
    5. remove detail from /etc/oratab
    5. drop ASM diskgroup
    For more detail following metalink notes.
    Note 239998.1: 10g RAC: How to Clean Up After a Failed CRS Install
    Note:311350.1 :How to cleanup ASM installation (RAC and Non-RAC)
    Note:251412.1 :How to Drop the Target Database Using RMAN
    Regards
    [email protected]

  • How to remove old vmm2012 server name from VMM Server navigation pane?

    After rename SCVMM2012(3.0.6040.0) old name leave in fabric VMM Server navigation pane "not responding" status. How to clean that from database safely?
    VMM and sql are in the same server. First i was rename VMM server, then sql instance, and Uninstall VMM with the Retain Data option. Library move new name correctly. Everything is work well after that, but only old vmm object leave in fabric. New name is
    responding status.
    Any ideas?

    I never tried that but Virtual Machine Recovery Tool for System Center 2012 maybe help you
    http://social.technet.microsoft.com/wiki/contents/articles/8953.using-the-virtual-machine-recovery-tool-for-system-center-2012-virtual-machine-manager-vmm.aspx
    Note: This program is not a supported part of the VMM product. This program is offered “as-is” and is documented only in this wiki. Please share any
    insights you gain by using the Virtual Machine Recovery Tool by updating this wiki page.
    Mohamed Fawzi | http://fawzi.wordpress.com

  • How to find old mailbox database name

    Hi,<o:p></o:p>
    We are using Exchange server 2007, we recently moved one user from one database to another database. But we didn't notice source database name while
    we move. After a week time user asking us to restore one month old data but now we didn't know were user was there earlier before moved to new database. Is there any way to find old mailbox database name for the particular user?<o:p></o:p>
    Your help is really appreciated. Thanks<o:p></o:p>

    Try this friend:
    Option1:
    get-mailbox [email protected] | Get-MailboxStatistics -IncludeMoveHistory | ft DisplayName, MoveHistory
    Option2:
    If you have trouble use below to generate in csv to get old DB status of user:
    $temp=Get-MailboxStatistics -Identity AylaKol -IncludeMoveReport
    $temp.MoveHistory[0] | Export-CSV C:\MoveReport_AylaKol.csv
    Option 3:
    C:\>(Get-MailboxStatistics alan.reid -IncludeMoveHistory).MoveHistory | select CompletionTimestamp,SourceDatabase,TargetDatabase | ft -auto
    CompletionTimestamp    SourceDatabase TargetDatabase
    14/07/2014 5:41:27 AM  MB-HO-04       DB01
    8/01/2014 11:35:55 AM  MB-HO-03       MB-HO-04
    11/09/2013 11:35:24 PM MB-HO-01       MB-HO-03

  • How To Remove A Specific Application Name From The "Open With" Dialog

    When you right click on a file you are presented with the "Open With" menu item and you are also presented with a list of applications that could potentially be used to open that file.
    In my case, when I click on a file of type .mov I am presented with the name of an application that I want to remove from the list, because that application ( Miro.app (2.5.2) ) no longer exists on my system.
    What is the best way to remove that application name from the list?

    Ok, but how does one remove some of the applications that are appear in the context menu for a given file type? Is there an asc file which can be edited?
    For example, in my system a PDF can be opened with over 10 applications. I would like to see just the three ones I use: Acrobat, Skim and Preview.
    Thanks in advance.

  • How to remove a modem/router name profanity

    Someone in our neighborhood has named their wireless modem/router with a name that includes profanity.  This name shows up as a connect option on my computer when I click to show network options.  It is irritating enough that they are invading my space by putting profanity on my machine but this also means that my children see the same profanity on their computer.  Does anyone know how I can make this wireless router NOT show up as an option on my children's computer?  (And on mine for that matter too.)
    AJ

    There's no way I know of to stop receiving that network name however you can remove airport icon from the menubar.  Then there's less chance of seeing it.
    You can remove it in System Preferences > Network > Click airport on the left > uncheck "Show airport status in the menubar".   Or hold cmd and drag it off the menubar.
    Regards,
    Captfred

  • How to remove "01. [song name]" recursively?

    There are several questions in his community that treat the same issue, but I have a different circumstance. I used different software to rip CDs and the actual file name has the track numbers in it. How do I remove this without having to get info on each individual song? (on a related note, how come iTunes doesn't have some rudimentary options for batch renaming songs for the most common problems?)
    Thanks

    If you use the "Keep..." option, found at Edit > Preferences > Advanced, iTunes will rename your files to the format "## Title" whenever it touches the file.
    If that option is off, iTunes does not change the filename at all.
    If you use a 3rd party program to rename your files, iTunes will lose them and you will have a mess.

  • How can find the reposite database name connection

    I have a obiee server installed, how can I find the reposite schema database coneection? -thanks

    Hi,
    You can create Repository Static Variable in rpd, and in Connection pool you can mention like VALUEOF(OLAP_DSN) and VALUEOF(OLAP_USER) in DSN and user name.Then create a report and change the function to use these variable.
    fyi..refer:
    http://oraclebi.blog.com/tip-of-the-day-checking-the-dsn-name-and-user-name-from-report-level/
    Thanks
    Deva

  • How to remove session scope?

    Hi,
    I instantiated a bean using the JSP useBean tag and set its session scope to session. I want to at one point be able to remove the bean from session, how can I do this?
    regards
    Siliconbt

    you make the bean object null then u can remove the session.
    the above answer given in my view
    if any pls forward to me

  • How to Change Crystal Report database name from visual basic code?

    Hi all,
    I have created a Crystal Report (CR)  with .NET VB. I also have developd some UDTs for that pusrpose and everything is OK.
    However I cannot use the same CR in another Company which has the same UDTs. I have not found how Connect to Company (in other words change the DB the report reads).
    Any Idea?
    Thanks,
    Vangelis
    Edited by: Vangelis Kanellopoulos on Jul 19, 2008 6:07 PM
    Edited by: Vangelis Kanellopoulos on Jul 20, 2008 10:27 AM
    Edited by: Vangelis Kanellopoulos on Jul 20, 2008 10:28 AM

    Hi Vangelis,
    Here's a simple VB class that has functions for setting the login details for the report and passing parameters.
    Option Strict Off
    Option Explicit On
    Public Class CrystalFunctions
        Enum ParamType As Integer
            Int
            Text
        End Enum
        Public Shared Sub SetCrystalLogin(ByVal sUser As String, ByVal sPassword As String, ByVal sServer As String, ByVal sCompanyDB As String, _
               ByRef oRpt As CrystalDecisions.CrystalReports.Engine.ReportDocument)
            Dim oDB As CrystalDecisions.CrystalReports.Engine.Database = oRpt.Database
            Dim oTables As CrystalDecisions.CrystalReports.Engine.Tables = oDB.Tables
            Dim oLogonInfo As CrystalDecisions.Shared.TableLogOnInfo
            Dim oConnectInfo As CrystalDecisions.Shared.ConnectionInfo = New CrystalDecisions.Shared.ConnectionInfo()
            oConnectInfo.DatabaseName = sCompanyDB
            oConnectInfo.ServerName = sServer
            oConnectInfo.UserID = sUser
            oConnectInfo.Password = sPassword
            ' Set the logon credentials for all tables
            For Each oTable As CrystalDecisions.CrystalReports.Engine.Table In oTables
                oLogonInfo = oTable.LogOnInfo
                oLogonInfo.ConnectionInfo = oConnectInfo
                oTable.ApplyLogOnInfo(oLogonInfo)
            Next
            ' Check for subreports
            Dim oSections As CrystalDecisions.CrystalReports.Engine.Sections
            Dim oSection As CrystalDecisions.CrystalReports.Engine.Section
            Dim oRptObjs As CrystalDecisions.CrystalReports.Engine.ReportObjects
            Dim oRptObj As CrystalDecisions.CrystalReports.Engine.ReportObject
            Dim oSubRptObj As CrystalDecisions.CrystalReports.Engine.SubreportObject
            Dim oSubRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
            oSections = oRpt.ReportDefinition.Sections
            For Each oSection In oSections
                oRptObjs = oSection.ReportObjects
                For Each oRptObj In oRptObjs
                    If oRptObj.Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
                        ' This is a subreport so set the logon credentials for this report's tables
                        oSubRptObj = CType(oRptObj, CrystalDecisions.CrystalReports.Engine.SubreportObject)
                        ' Open the subreport
                        oSubRpt = oSubRptObj.OpenSubreport(oSubRptObj.SubreportName)
                        oDB = oSubRpt.Database
                        oTables = oDB.Tables
                        For Each oTable As CrystalDecisions.CrystalReports.Engine.Table In oTables
                            oLogonInfo = oTable.LogOnInfo
                            oLogonInfo.ConnectionInfo = oConnectInfo
                            oTable.ApplyLogOnInfo(oLogonInfo)
                        Next
                    End If
                Next
            Next
        End Sub
        Public Shared Sub SetCrystalParams(ByVal sFieldName As String, ByVal iDataType As ParamType, ByVal sVal As String, ByRef oRpt As CrystalDecisions.CrystalReports.Engine.ReportDocument)
            Dim oFieldDefs As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinitions
            Dim oFieldDef As CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition
            Dim oParamVals As CrystalDecisions.Shared.ParameterValues
            Dim oDiscreteVal As CrystalDecisions.Shared.ParameterDiscreteValue
            oFieldDefs = oRpt.DataDefinition.ParameterFields
            oFieldDef = oFieldDefs(sFieldName)
            oParamVals = oFieldDef.CurrentValues
            oParamVals.Clear()
            oDiscreteVal = New CrystalDecisions.Shared.ParameterDiscreteValue()
            Select Case iDataType
                Case ParamType.Int
                    oDiscreteVal.Value = System.Convert.ToInt32(sVal)
                Case ParamType.Text
                    oDiscreteVal.Value = sVal
            End Select
            oParamVals.Add(oDiscreteVal)
            oFieldDef.ApplyCurrentValues(oParamVals)
        End Sub
    End Class
    And here's how you would use them:
    ' Create an instance of the Crystal report
    _rptCrystal = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
    _rptCrystal.Load(_oSBO.AddonPath + "\Reports\MyReport.rpt")
    ' Call SetCrystalLogin to see the logon information for all report tables
    CrystalFunctions.SetCrystalLogin(sUser, sPassword, _oSBO.SboCompany.Server, _oSBO.SboCompany.CompanyDB, _rptCrystal)
    ' Set my report parameter value
    CrystalFunctions.SetCrystalParams("MyParam", CrystalFunctions.ParamType.Int, 999, _rptCrystal)
    ' Print the report straight to the printer                          
    _rptCrystal.PrintToPrinter(1, False, 0, 0)
    The other way to approach this solution would be to base your Crystal report on a .NET dataset rather than a database connection. However, as you've already written your report, the code above is going to be simpler to implement.
    Kind Regards,
    Owen

  • How to get database name

    How do i get the database name in reports. we can get this in form by get_application_property, do we have anything like that in reports
    thanks

    Check the database dictionary tables.
    sys.v_$parameter certainly contains a parameter with the name 'db_name'and the value of the database name.
    see what you get when you run:
    select * from sys.v_$parameter where name='db_name'
    If the user running the report won't have the select priviledge on sys.v_$parameter, then you will have to create a function that returns the value for the db_name parameter (that is in the schema of a user that has that priviledge) and grant execute on it to the user that runs the report and create a synonym for that function.

  • How to know the database name?

    I have installed oracle 10g and developer suite.. I am trying to create forms now.
    But its error out: TNS: could not resolve the connect identifier specified!!!
    I forgot the Data base name.. How can I know the database name??
    Thanks in Advance!!!!!!!!!!

    I have installed oracle 10g and developer suite.. I'm sorry, but you are going to have be more specific as what you installed!
    If you installed Oracle Database 10g Express Edition then it is not (by default) configured to allow a connection through SQL*Plus. It is primarily configured to open a connection through the "Go To Database Homepage" url/link in the Start Menu => Oracle Database 10g Express Edition => Go To Database Homepage. In order to connect to the database from SQL*Plus (which is included with Oracle Developer Suite 10g) you will need to run the Net Configuration Assistant to configure your TNSNAMES.ora and SQLNET.ora files. Go to Start Menu => Oracle - DevSuiteHome1 => Configuration and Migration Tools => Net Configuration Assistant to run the assistant. After you run the assistant, test to make sure can connect through SQL*Plus before you attempt to connect through Forms.
    Hope this helps,
    Craig...

  • How to find Logical database name using selection view

    Hi Experts,
                      How can we find logical database name using selection view in se36.
    Regards,
    Mani

    Hi,
    If you want to see the logincal database used in the report ( tcode se38) in the intial screen select the attribute tab
    and click display you will bw able to see the logical datbase ysed for the report.
    Thanks.

Maybe you are looking for