{"id":2466,"date":"2013-03-07T12:22:51","date_gmt":"2013-03-07T12:22:51","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=2466"},"modified":"2013-03-21T08:10:24","modified_gmt":"2013-03-21T08:10:24","slug":"%e6%95%b0%e6%8d%ae%e5%ba%93%e7%bc%93%e5%ad%98","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2013\/03\/07\/%e6%95%b0%e6%8d%ae%e5%ba%93%e7%bc%93%e5%ad%98\/","title":{"rendered":"\u6570\u636e\u5e93\u7f13\u5b58"},"content":{"rendered":"<p><span style=\"font-size: 12px;\">SqlDependency\u7c7b\u6709\u4e00<\/span><span style=\"font-size: 12px; color: rgb(68, 68, 68); font-family: Arial, Helvetica, sans-serif; line-height: 24px; background-color: rgb(255, 255, 255);\">OnChangeEventHandler\u65b9\u6cd5\uff0c\u53ef\u6ce8\u518c<\/span><span style=\"color: rgb(51, 51, 51); font-family: 'Courier New', monospace; font-size: 12px; line-height: 28px; text-indent: 28px; white-space: pre; background-color: rgb(230, 230, 230);\">\u59d4\u6258\uff0c<\/span><span style=\"font-size: 12px; color: rgb(68, 68, 68); font-family: Arial, Helvetica, sans-serif; line-height: 24px; background-color: rgb(255, 255, 255);\">\u5f53\u63a5\u6536\u5230\u6539\u53d8\u65f6\uff0c\u7528<\/span><span style=\"color: rgb(51, 51, 51); font-family: 'Courier New', monospace; font-size: 12px; line-height: 28px; text-indent: 28px; white-space: pre; background-color: rgb(230, 230, 230);\">\u59d4\u6258<\/span><span style=\"font-size: 12px; color: rgb(68, 68, 68); font-family: Arial, Helvetica, sans-serif; line-height: 24px; background-color: rgb(255, 255, 255);\">\u5b9e\u65bd\u6570\u636e\u66f4\u6539\u81ea\u52a8\u901a\u77e5\u524d\u53f0<\/span><br \/>\n<span style=\"font-size: 12px;\">\u4f8b\uff1a<a href=\"http:\/\/www.360doc.com\/content\/09\/0609\/16\/32573_3830694.shtml\">http:\/\/www.360doc.com\/content\/09\/0609\/16\/32573_3830694.shtml<\/a><br \/>\n\u7528\u6b64\u65b9\u6cd5\u53ef\u5b9e\u73b0\u5220\u9664\u8fc7\u671f\u7684\u7f13\u5b58\u3002\u8981\u6ce8\u610f\u7684<\/span><span style=\"font-size:12px;\">\u662fcommand \u6307\u5b9a\u7684 commandText \u7684\u67e5\u8be2\u7ed3\u679c\u53d1\u751f\u53d8\u5316\u65f6\u89e6\u53d1 OnChange\uff0c\u4e14\u53ea\u89e6\u53d1\u4e00\u6b21\uff0c\u6545\u9700\u8981\u5728\u89e6\u53d1\u4e8b\u4ef6\u4e2d\u518d\u6b21\u5efa\u7acb\u4f9d\u8d56\u548c\u7ed1\u5b9a\u63a5\u53d7\u901a\u77e5.<\/span><span style=\"font-size:8px;\">sqlDependency start\u540e\uff0c\u4f1a\u5f00\u6237\u4e00\u4e2a\u7ebf\u7a0b\u7b49\u5f85\uff0c\u5f53\u901a\u77e5\u7531\u670d\u52a1\u5668\u7684service Broker\u4f20\u6765\u7684\u65f6\u5019\uff0c\u7ebf\u7a0b\u6536\u5230\u4fe1\u606f\uff0c\u8c03\u7528\u56de\u8c03\u51fd\u6570<\/span><\/p>\n<div>\n\t<span style=\"font-size:8px;\">sqlDependency\u7684start\u4e0estop\u90fd\u662f\u63a7\u5236\u7ebf\u7a0b\u7684\u5f00\u5173\uff0c\u6ce8\u610f\u6b64\u7ebf\u7a0b\u662f\u5168\u5c40\u6027\u7684\uff0c\u5171\u4eab\u3002<\/span><\/div>\n<p>\n<span style=\"font-size: 12px;\">\u4e0d\u8fc7.net\u540c\u65f6\u6709<\/span><span style=\"font-size: 12px;\">SqlCacheDependency\uff0c\u53ef\u81ea\u52a8\u5b8c\u6210\u5220\u9664\u7f13\u5b58\u7684\u64cd\u4f5c\u3002<\/span><\/p>\n<p>\u76f8\u5173sql:<\/p>\n<div>\n\t&#8211;\u8ba2\u9605<\/div>\n<div>\n\t&#8211;\u5728\u505a\u51fa\u901a\u77e5\u540e\uff0c\u4f1a\u8fdb\u884c\u5220\u9664\uff0c\u6240\u4ee5\u9700\u8981\u91cd\u65b0\u8ba2\u9605<\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\tselect * from sys.dm_qn_subscriptions<\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t&#8211;\u4fe1\u606f\u5bf9\u63a5<\/div>\n<div>\n\tSELECT TOP 50 *&nbsp;<\/div>\n<div>\n\tFROM sys.transmission_queue<\/p>\n<div>\n\t\t&#8211;\u5173\u6389\u8ba2\u9605<\/div>\n<div>\n\t\tKILL QUERY NOTIFICATION SUBSCRIPTION &nbsp;10<\/div>\n<\/div>\n<p>\n<span style=\"font-size:12px;\">\u8981\u8fbe\u5230\u7684\u6548\u679c\uff1a<br \/>\n\u5c06\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u653e\u5230\u7f13\u5b58\u4e2d\uff0c\u5f53\u6570\u636e\u53d8\u5316\u65f6\uff0c\u81ea\u52a8\u901a\u8fc7\u5e94\u7528\u5220\u9664\u7f13\u5b58<br \/>\nSql server 7.0\/2000\u4e0b SqlCacheDependency\u4f7f\u7528\u8f6e\u8be2\u7684\u65b9\u5f0f\u8fdb\u884c\u7f13\u5b58\u5931\u6548\u68c0\u67e5\uff0c<br \/>\nSql server 2005\/2008\u4e0b\u589e\u52a0\u4f7f\u7528\u67e5\u8be2\u901a\u77e5\u65b9\u5f0f\u8fdb\u884c\u7f13\u5b58\u5931\u6548\u68c0\u67e5\u3002<\/span><\/p>\n<p><span style=\"font-size:12px;\">\u5b9e\u65bd\uff1a<\/span><br \/>\n<span style=\"font-size:8px;\">\u53c2\u8003\uff1a<a href=\"http:\/\/space.itpub.net\/16436858\/viewspace-630489\">http:\/\/space.itpub.net\/16436858\/viewspace-630489<\/a><br \/>\n<a href=\"http:\/\/www.cnblogs.com\/over140\/archive\/2009\/01\/15\/1376318.html\">http:\/\/www.cnblogs.com\/over140\/archive\/2009\/01\/15\/1376318.html<\/a><\/span><\/p>\n<p style=\"word-break: break-all; line-height: 21.59375px; margin: 10px 0px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);\">\n\t1.\u68c0\u6d4b\u662f\u5426\u5df2\u7ecf\u542f\u7528Service Broker<\/p>\n<p style=\"word-break: break-all; line-height: 21.59375px; margin: 10px 0px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);\">\n\t&nbsp; Select DATABASEpRoPERTYEX(&#39;\u6570\u636e\u5e93\u540d\u79f0&#39;,&#39;IsBrokerEnabled&#39;)&nbsp; &#8212; 1 \u8868\u793a\u5df2\u7ecf\u542f\u7528 0 \u8868\u793a\u6ca1\u6709\u542f\u7528<\/p>\n<p style=\"word-break: break-all; line-height: 21.59375px; margin: 10px 0px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);\">\n\t2.\u542f\u7528Service Broker &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<\/p>\n<p style=\"word-break: break-all; line-height: 21.59375px; margin: 10px 0px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);\">\n\t&nbsp; ALTER DATABASE&nbsp;<a href=\"\" style=\"word-break: break-all; color: rgb(102, 102, 102); line-height: normal !important;\" target=\"_self\"><u style=\"word-break: break-all;\"><strong style=\"word-break: break-all;\">\u6570\u636e\u5e93<\/strong><\/u><\/a>\u540d\u79f0 SET ENABLE_BROKER;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p><\/p>\n<div>\n\t&nbsp;&#8211;WITH ROLLBACK IMMEDIATE;<\/div>\n<div>\n\tGO<\/div>\n<div>\n\t&nbsp;<\/div>\n<p style=\"word-break: break-all; line-height: 21.59375px; margin: 10px 0px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);\">\n\t3.\u7ed9\u60a8\u7684\u6570\u636e\u5e93\u8bbf\u95ee\u5e10\u53f7\u6388\u4e88\u6743\u9650<\/p>\n<p style=\"word-break: break-all; line-height: 21.59375px; margin: 10px 0px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);\">\n\t&nbsp; GRANT SUBSCRIBE QUERY NOTIFICATIONS TO test<\/p>\n<p style=\"word-break: break-all; line-height: 21.59375px; margin: 10px 0px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);\">\n\t&nbsp; \u6ce8\u610f\uff1a\u8fd9\u4e00\u6b65\u975e\u5e38\u91cd\u8981, \u5982\u679c\u6ca1\u6709\u6743\u9650, \u6570\u636e\u5e93\u6539\u53d8\u7684\u901a\u77e5\u5c06\u65e0\u6cd5\u63a5\u6536, cache\u6c38\u8fdc\u90fd\u4e0d\u4f1a\u88ab\u5237\u65b0\uff0c\u6ce8\u610f sa\u6388\u6b64\u6743\u9650(ms\u7981\u6b62)\uff0c \u6240\u4ee5\uff0c\u6362\u4e2a\u6570\u636e\u5e93\u8bbf\u95ee\u5e10\u53f7\u5373\u53ef.<br \/>\n\t\u6216\u8005\u7528\uff1a<span class=\"kwd\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; color: rgb(0, 0, 139);\">alter<\/span><span class=\"pln\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;\"> <\/span><span class=\"kwd\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; color: rgb(0, 0, 139);\">authorization<\/span><span class=\"pln\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;\"> <\/span><span class=\"kwd\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; color: rgb(0, 0, 139);\">on<\/span><span class=\"pln\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;\"> <\/span><span class=\"kwd\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; color: rgb(0, 0, 139);\">database<\/span><span class=\"pun\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;\">::[&lt;<\/span><span class=\"pln\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;\">your_SSB_DB<\/span><span class=\"pun\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;\">&gt;]<\/span><span class=\"pln\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;\"> <\/span><span class=\"kwd\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; color: rgb(0, 0, 139);\">to<\/span><span class=\"pln\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;\"> <\/span><span class=\"pun\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;\">[<\/span><span class=\"pln\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;\">sa<\/span><span class=\"pun\" style=\"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; background-color: transparent; line-height: 18px; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline;\">];<\/span><br \/>\n\t4\uff0c\u7f13\u5b58\u4ee3\u7801<\/p>\n<p><\/p>\n<div>\n\t\/\/\/ &lt;summary&gt;<\/div>\n<div>\n\t&nbsp; &nbsp; \/\/\/ \u8bbe\u7f6e\u8868\u4f9d\u8d56\u7f13\u5b58<\/div>\n<div>\n\t&nbsp; &nbsp; \/\/\/ &lt;\/summary&gt;<\/div>\n<div>\n\t&nbsp; &nbsp; public static DataTable GetTableCache(string TableName, string CacheDataBase,string ConnStr)<\/div>\n<div>\n\t&nbsp; &nbsp; {<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; System.Web.Caching.Cache objCache = HttpRuntime.Cache;<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; DataTable dt = new DataTable();<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; \/\/objCache.Insert(CacheKey, objObject);<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; if (objCache[TableName] == null)<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/get from database<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DataSet ds = new DataSet();<\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlDependency.Start(ConnStr);\/\/\u542f\u52a8\u4e0e\u5173\u95ed\u653e\u5728Global\u7684Application_Start,End\u4e2d\u597d\u4e00\u4e9b<\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using (SqlConnection connection = new SqlConnection(ConnStr))<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/\u53ea\u6709sql\u4e2d\u6307\u5b9a\u7684\u5b57\u6bb5\u53d1\u751f\u66f4\u6539\u65f6\u624d\u4f1a\u63d0\u9192\u3002<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string sql = string.Format(&quot; SELECT ID,ParentID,Name,OrderBy,OrganID FROM dbo.mdCity&quot;);<\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using (SqlCommand command = new SqlCommand(sql, connection))<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlCacheDependency dependency = new SqlCacheDependency(command);<\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/using (SqlDataAdapter adapter = new SqlDataAdapter()) \/\/\u67e5\u8be2\u6570\u636e<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/{<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ &nbsp; &nbsp;adapter.SelectCommand = command;<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ &nbsp; &nbsp;adapter.Fill(ds);<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/}<\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/HttpRuntime.Cache.Insert(&quot;EntityResourceCollection&quot;, ds, dependency);<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; connection.Open();<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dt.Load(command.ExecuteReader(CommandBehavior.CloseConnection));<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objCache.Insert(TableName, dt, dependency);<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; else<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dt = (DataTable)objCache[TableName];<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>\n\t&nbsp;<\/div>\n<div>\n\t&nbsp; &nbsp; &nbsp; &nbsp; return dt;<\/div>\n<div>\n\t&nbsp; &nbsp; }<\/p>\n<p>\t5,\u6ce8\u610f \u53ea\u6709sql\u4e2d\u6307\u5b9a\u5b57\u6bb5\u53d1\u751f\u66f4\u6539\u65f6\u624d\u4f1a\u63d0\u9192\u3002<\/p>\n<div>\n\t\t\u5173\u4e8eSqlDependency\u7c7b\uff0c\u5b83\u7684\u9650\u5236\u5f88\u591a\uff0c\u7279\u522b\u8981\u6ce8\u610f\u7684\u5c31\u662fcommand\u7684sql\u8bed\u53e5\u95ee\u9898:<\/div>\n<div>\n\t\tselect id,name from dbo.test where id&lt;&gt;4 order by id desc&nbsp;<\/div>\n<div>\n\t\t\u4ed6\u53ea\u80fd\u652f\u6301\u4e0a\u9762\u8fd9\u6837\u7684\u7b80\u5355\u8bed\u53e5<\/div>\n<div>\n\t\t\u8868\u540d\u524d\u9700\u8981\u67b6\u6784\u540d\uff0c\u5982dbo<\/p>\n<p>\t\t<strong><a href=\"http:\/\/msdn.microsoft.com\/zh-cn\/library\/ms181122(sql.90).aspx\">sql\u6ce8\u610f<\/a><\/strong><\/p>\n<p style=\"color: rgb(42, 42, 42); margin-top: 0px; margin-bottom: 0px; padding-bottom: 15px; line-height: 18px; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px;\">\n\t\t\t\u6ee1\u8db3\u4e0b\u5217\u8981\u6c42\u7684 SELECT \u8bed\u53e5\u652f\u6301\u67e5\u8be2\u901a\u77e5\uff1a<\/p>\n<ul style=\"font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 16px;\">\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u5fc5\u987b\u663e\u5f0f\u8bf4\u660e SELECT \u8bed\u53e5\u4e2d\u63d0\u53d6\u7684\u5217\uff0c\u5e76\u4e14\u8868\u540d\u5fc5\u987b\u9650\u5b9a\u4e3a\u4e24\u90e8\u5206\u7ec4\u6210\u7684\u540d\u79f0\u3002\u6ce8\u610f\uff0c\u8fd9\u610f\u5473\u7740\u8bed\u53e5\u4e2d\u5f15\u7528\u7684\u6240\u6709\u8868\u90fd\u5fc5\u987b\u5904\u4e8e\u540c\u4e00\u6570\u636e\u5e93\u4e2d\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u4f7f\u7528\u661f\u53f7 (*) \u6216&nbsp;<em>table_name<\/em>.* \u8bed\u6cd5\u6307\u5b9a\u5217\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u4f7f\u7528\u672a\u547d\u540d\u5217\u6216\u91cd\u590d\u7684\u5217\u540d\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u5fc5\u987b\u5f15\u7528\u57fa\u8868\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5f15\u7528\u5177\u6709\u8ba1\u7b97\u5217\u7684\u8868\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u5728 SELECT \u8bed\u53e5\u4e2d\u63d0\u53d6\u7684\u5217\u4e0d\u80fd\u5305\u542b\u805a\u5408\u8868\u8fbe\u5f0f\uff0c\u9664\u975e\u8bed\u53e5\u4f7f\u7528 GROUP BY \u8868\u8fbe\u5f0f\u3002\u63d0\u4f9b GROUP BY \u8868\u8fbe\u5f0f\u65f6\uff0c\u9009\u62e9\u5217\u8868\u4fbf\u53ef\u4ee5\u5305\u542b\u805a\u5408\u51fd\u6570 COUNT_BIG() \u6216 SUM()\u3002\u4f46\u662f\uff0c\u4e0d\u80fd\u4e3a\u53ef\u4e3a\u7a7a\u7684\u5217\u6307\u5b9a SUM()\u3002\u8bed\u53e5\u4e0d\u80fd\u6307\u5b9a HAVING\u3001CUBE \u6216 ROLLUP\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u5728\u7528\u4f5c\u7b80\u5355\u8868\u8fbe\u5f0f\u7684 SELECT \u8bed\u53e5\u4e2d\u63d0\u53d6\u7684\u5217\u4e0d\u80fd\u591a\u6b21\u663e\u793a\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5305\u542b PIVOT \u6216 UNPIVOT \u8fd0\u7b97\u7b26\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5305\u542b UNION\u3001INTERSECT \u6216 EXCEPT \u8fd0\u7b97\u7b26\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5f15\u7528\u89c6\u56fe\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5305\u542b\u4e0b\u5217\u4efb\u610f\u4e00\u4e2a\uff1aDISTINCT\u3001COMPUTE\u3001COMPUTE BY \u6216 INTO\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5f15\u7528\u670d\u52a1\u5668\u5168\u5c40\u53d8\u91cf (@@<em>variable_name<\/em>)\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5f15\u7528\u6d3e\u751f\u8868\u3001\u4e34\u65f6\u8868\u6216\u8868\u53d8\u91cf\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u4ece\u5176\u4ed6\u6570\u636e\u5e93\u6216\u670d\u52a1\u5668\u4e2d\u5f15\u7528\u8868\u6216\u89c6\u56fe\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5305\u542b\u5b50\u67e5\u8be2\u3001\u5916\u90e8\u8054\u63a5\u6216\u81ea\u8054\u63a5\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5f15\u7528\u4e0b\u5217\u5927\u578b\u5bf9\u8c61\u7c7b\u578b\uff1a<strong>text<\/strong>\u3001<strong>ntext<\/strong>&nbsp;\u548c&nbsp;<strong>image<\/strong>\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u4f7f\u7528 CONTAINS \u6216 FREETEXT \u5168\u6587\u8c13\u8bcd\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u4f7f\u7528\u884c\u96c6\u51fd\u6570\uff0c\u5305\u62ec OPENROWSET \u548c OPENQUERY\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u4f7f\u7528\u4e0b\u5217\u4efb\u4f55\u4e00\u4e2a\u805a\u5408\u51fd\u6570\uff1aAVG\u3001COUNT(*)\u3001MAX\u3001MIN\u3001STDEV\u3001STDEVP\u3001VAR \u6216 VARP\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u4f7f\u7528\u4efb\u4f55\u5177\u6709\u4e0d\u786e\u5b9a\u6027\u7684\u51fd\u6570\uff0c\u5305\u62ec\u6392\u540d\u51fd\u6570\u548c\u7a97\u53e3\u51fd\u6570\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5305\u542b\u7528\u6237\u5b9a\u4e49\u805a\u5408\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5f15\u7528\u7cfb\u7edf\u8868\u6216\u89c6\u56fe\uff0c\u5305\u62ec\u76ee\u5f55\u89c6\u56fe\u548c\u52a8\u6001\u7ba1\u7406\u89c6\u56fe\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5305\u542b FOR BROWSE \u4fe1\u606f\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5f15\u7528\u961f\u5217\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5305\u542b\u65e0\u6cd5\u66f4\u6539\u548c\u65e0\u6cd5\u8fd4\u56de\u7ed3\u679c\u7684\u6761\u4ef6\u8bed\u53e5\uff08\u5982 WHERE 1=0\uff09\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u6307\u5b9a READPAST \u9501\u63d0\u793a\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5f15\u7528\u4efb\u4f55 Service Broker QUEUE\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5f15\u7528\u540c\u4e49\u8bcd\u3002<\/li>\n<li style=\"list-style-image: none;\">\n\t\t\t\t\u8bed\u53e5\u4e0d\u80fd\u5177\u6709\u57fa\u4e8e double\/real \u6570\u636e\u7c7b\u578b\u7684\u6bd4\u8f83\u6216\u8868\u8fbe\u5f0f\u3002<\/li>\n<\/ul><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>SqlDependency\u7c7b\u6709\u4e00OnChangeEventHandler\u65b9\u6cd5\uff0c\u53ef\u6ce8\u518c\u59d4\u6258\uff0c\u5f53\u63a5\u6536\u5230\u6539\u53d8\u65f6\uff0c\u7528\u59d4 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-2466","post","type-post","status-publish","format-standard","hentry","category-aspdotnet"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/2466","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=2466"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/2466\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=2466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=2466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=2466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}