{"id":2867,"date":"2013-10-24T06:11:18","date_gmt":"2013-10-24T06:11:18","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=2867"},"modified":"2013-10-24T06:21:55","modified_gmt":"2013-10-24T06:21:55","slug":"%e5%bc%82%e5%b8%b8%e8%bf%9e%e6%8e%a5%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2013\/10\/24\/%e5%bc%82%e5%b8%b8%e8%bf%9e%e6%8e%a5%e6%95%b0%e6%8d%ae%e5%ba%93\/","title":{"rendered":"\u5f02\u5e38\u8fde\u63a5\u6570\u636e\u5e93"},"content":{"rendered":"<pre class=\"brush:sql;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;\">\r\n<\/pre>\n<div>\n<pre class=\"brush:sql;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;\">\r\nSELECT CONVERT(VARCHAR(50),CONNECTIONPROPERTY(&#39;local_net_address&#39;))host ,client_net_address,program_name,db.NAME,convert(varchar(max),t.[text]) SQLText,CONVERT(varchar(20),login_time,120) login_time,<\/pre>\n<\/div>\n<div>\n\tCONVERT(VARCHAR(20),last_request_end_time,120) last_request_end_time,login_name,s.session_id<\/div>\n<p>FROM master.sys.dm_exec_sessions AS s (nolock)<br \/>\n\tINNER JOIN master.sys.dm_exec_connections AS c (nolock) ON s.session_id=c.session_id<br \/>\n\tINNER JOIN master.sys.databases db ON s.database_id = db.database_id<br \/>\n\tOUTER APPLY master.sys.dm_exec_sql_text(c.most_recent_sql_handle) AS t<br \/>\n\tLEFT JOIN dbo.mdSystemIP msi ON client_net_address = msi.IP<br \/>\n\tWHERE<br \/>\n\tNOT EXISTS( &#8211;\u975e\u9650\u5b9aIP\u8bbf\u95ee<br \/>\n\t\tSELECT 1 FROM dbo.mdSystemIP ms WHERE client_net_address = ms.IP<br \/>\n\t )<br \/>\n\t OR <\/p>\n<p>\t  ( &#8211;\u670d\u52a1\u5668\u8bbf\u95ee\u4f46\u662f\u975e\u5408\u6cd5\u5ba2\u6237\u7aef\uff0c\u5305\u542b\u7528ssms\u76f4\u8054\u4e5f\u662f\u4e0d\u5408\u6cd5<br \/>\n\t\tEXISTS(SELECT 1 FROM dbo.mdSystemIP ms WHERE client_net_address = ms.IP AND VisitType=&#39;Server&#39;)<br \/>\n\t\tAND program_name NOT LIKE &#39;.Net SqlClient Data Provider%&#39; &#8211;\u7a0b\u5e8f\u8fde\u63a5<br \/>\n\t\tAND program_name NOT LIKE &#39;SqlQuery%&#39;  &#8211;\u7f13\u5b58\uff0c\u6570\u636e\u5e93\u4f9d\u8d56<br \/>\n\t\tAND program_name NOT LIKE &#39;SQLAgent%&#39; &#8211;job<br \/>\n\t\tAND program_name NOT LIKE &#39;Repl%&#39;  &#8211;\u590d\u5236\u5206\u53d1<br \/>\n\t\tAND program_name NOT LIKE &#39;DATABASE%&#39;  &#8211;\u590d\u5236\u5206\u53d1<br \/>\n\t\tAND program_name NOT LIKE &#39;SQLCLUSTER%&#39;  &#8211;\u590d\u5236\u5206\u53d1<br \/>\n\t\tAND program_name != &#39;Microsoft SQL Server&#39; &#8211;\u81ea\u8eab\u6267\u884c<br \/>\n\t\tAND program_name != &#39;Microsoft&reg; Windows&reg; Operating System&#39;<br \/>\n\t\tAND login_name != &#39;NT AUTHORITY\\SYSTEM&#39;<br \/>\n\t\tAND db.NAME NOT IN(&#39;master&#39;,&#39;msdb&#39;,&#39;distribution&#39;)<br \/>\n\t )<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SELECT CONVERT(VARCHAR(50),CONNECTIONPROPERTY(&#39;loca [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-2867","post","type-post","status-publish","format-standard","hentry","category-sql-server"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/2867","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=2867"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/2867\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=2867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=2867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=2867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}