sql SQL Server问题疑难解答

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql SQL Server问题疑难解答相关的知识,希望对你有一定的参考价值。

/*********************************
FINDING OPEN TRANSACTIONS AND KILLING THEM
**********************************/

/*
If you fail to commit a transaction, it'll lock the table. To see which transactions are open, you can use DBCC OPENTRAN (Database Console Commands). 
OPENTRAN will show you the oldest open transaction. You can then use the KILL keyword to terminate the transaction (this'll also terminate the connection).
*/
DBCC OPENTRAN;

KILL 52; -- 52 is the server process ID for the transaction as listed on the 'SPID (server process ID):' line of DBCC OPENTRAN

/*********************************
HOW TO SEE WHAT QUERIES ARE BEING SENT TO THE DATABASE
**********************************/

/*
One method is to go to Tools and select SQL Server Profiler. You can then create a trace which will show all code hitting the database, including from other
users and applications.

A second method involves the following query which will show you queries based on session information (doesn't always work?).
*/
SELECT sdest.DatabaseName 
    ,sdes.session_id
    ,sdes.[host_name]
    ,sdes.[program_name]
    ,sdes.client_interface_name
    ,sdes.login_name
    ,sdes.login_time
    ,sdes.nt_domain
    ,sdes.nt_user_name
    ,sdec.client_net_address
    ,sdec.local_net_address
    ,sdest.ObjName
    ,sdest.Query
FROM sys.dm_exec_sessions AS sdes
INNER JOIN sys.dm_exec_connections AS sdec ON sdec.session_id = sdes.session_id
CROSS APPLY (
    SELECT db_name(dbid) AS DatabaseName
        ,object_id(objectid) AS ObjName
        ,ISNULL((
                SELECT TEXT AS [processing-instruction(definition)]
                FROM sys.dm_exec_sql_text(sdec.most_recent_sql_handle)
                FOR XML PATH('')
                    ,TYPE
                ), '') AS Query

    FROM sys.dm_exec_sql_text(sdec.most_recent_sql_handle)
    ) sdest
where sdes.session_id <> @@SPID

以上是关于sql SQL Server问题疑难解答的主要内容,如果未能解决你的问题,请参考以下文章

疑难解答'建立与SQL Server的连接时发生的与网络相关或特定于实例的错误'连接到Azure SQL Server

SQL Server--疑难杂症之坑爹的Windows故障转移群集

SQL Server 数据库启动过程(用户数据库加载过程的疑难杂症)

SQL Server Service Broker 的缺点 [关闭]

关于SQL Server 2000 Varchar长度的一个问题!!请高手解答

SQL 2005 用IP连接时 提示发生内部连接致命错误 这是为啥?我重装了SQL server2005后还是这样 求解答