<?xml version="1.0" encoding="gb2312"?>
<rss version="2.0">
<channel>
<title><![CDATA[c&#39;s blog]]></title>
        <image>
        <title>http://hi.baidu.com</title>
        <link>http://hi.baidu.com</link>
        <url>http://img.baidu.com/img/logo-hi.gif</url>
        </image>
<description><![CDATA[Writing about what I want to write about instead of just writing about it!]]></description>
<link>http://hi.baidu.com/zcsong85</link>
<language>zh-cn</language>
<generator>www.baidu.com</generator>
<ttl>5</ttl>


<item>
        <title><![CDATA[说说回车键触发表单提交的问题 By 大米(zz)]]></title>
        <link><![CDATA[http://hi.baidu.com/zcsong85/blog/item/96c120ec05b7f62d62d09faa.html]]></link>
        <description><![CDATA[
		
		<p>我们有时候希望回车键敲在文本框（input element）里来提交表单（form），但有时候又不希望如此。比如搜索行为，希望输入完关键词之后直接按回车键立即提交表单，而有些复杂表单，可能要避免回车键误操作在未完成表单填写的时候就触发了表单提交。</p>
<p>要控制这些行为，不需要借助JS，浏览器已经帮我们做了这些处理，这里总结几条规则：<br>
1、如果表单里有一个type=&rdquo;submit&rdquo;的按钮，回车键生效。<br>
2、如果表单里只有一个type=&rdquo;text&rdquo;的input，不管按钮是什么type，回车键生效。<br>
3、如果按钮不是用input，而是用button，并且没有加type，IE下默认为type=button，FX默认为type=submit。<br>
4、其他表单元素如textarea、select不影响，radio checkbox不影响触发规则，但本身在FX下会响应回车键，在IE下不响应。<br>
5、type=&rdquo;image&rdquo;的input，效果等同于type=&rdquo;submit&rdquo;，不知道为什么会设计这样一种type，不推荐使用，应该用CSS添加背景图合适些。</p>
<p>实际应用的时候，要让表单响应回车键很容易，保证表单里有个type=&rdquo;submit&rdquo;的按钮就行。而当只有一个文本框又不希望响应回车键怎么办呢？我的方法有点别扭，就是再写一个无意义的文本框，隐藏起来。根据第3条规则，我们在用button的时候，尽量显式声明type以使浏览器表现一致。</p> <a href="http://hi.baidu.com/zcsong85/blog/item/96c120ec05b7f62d62d09faa.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/zcsong85/blog/category/web%BF%AA%B7%A2">web开发</a>&nbsp;<a href="http://hi.baidu.com/zcsong85/blog/item/96c120ec05b7f62d62d09faa.html#comment">查看评论</a>]]></description>
        <pubDate>2009-11-06  12:37</pubDate>
        <category><![CDATA[web开发]]></category>
        <author><![CDATA[zcsong85]]></author>
		<guid>http://hi.baidu.com/zcsong85/blog/item/96c120ec05b7f62d62d09faa.html</guid>
</item>

<item>
        <title><![CDATA[道教养生zz-李一道长教练功视频(太一站樁、太一导引术)]]></title>
        <link><![CDATA[http://hi.baidu.com/zcsong85/blog/item/fc97175162207c2e42a75bd8.html]]></link>
        <description><![CDATA[
		
		<p><font size="5">视 频：&nbsp;&nbsp;</font></p>
<p><span><font size="5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  道友分享---太一导引术 </font></span></p>
<div>
<div>
<p><span><font size="5">(网 <span><span><span><font style="font-size: 16px"><font size="5">址：</font></font></span></span></span><a href="http://you.video.sina.com.cn/b/20611516-1442720673.html"><font color="#ae0405" size="2">http://you.video.sina.com.cn/b/20611516-1442720673.html</font></a>)</font></span></p>
<p><span><font size="4">太一按摩导引术，传承道教太一道，习此术不分男女老少，不受任何条件限制，只要持之以恒，定生奇效。通过它的锻炼，可使你气色红润，容光焕发，还可治疗神经衰弱，增强记忆力，同时对脏腑、四肢以及全身起到舒筋活血、通经络、除风湿、预防各种疾病的良好效果。全套共十五式。<br>
<br>
预备式：两脚平站，与肩与宽，头正身直，全身放松，舌顶上腭，双目平视，面含微笑。(行动不便之特殊者，可采用坐式)。<br>
<br>
第一式：布气摩面。将双手用力搓热，意想双手间真气灌满，有一灼热的火球，在手间摩擦(冬天，先把手放在热水袋上暖热)使双手掌生物场电位快速上升，然后分别放于脸上，意想脸部皱纹展开，气色红润，容光焕发，1分钟，然后双手由里向外摩面九圈。<br>
<br>
功能：能使你面色红润，肌肤细腻，清除皱纹，祛除面部色素、雀斑等面部疾病，有返老还童之功效，是古代驻颜术的基本功。<br>
<br>
第二式：夹鼻。深吸一口气后，口闭，用双手掌缘夹住鼻部，向外出气，待气灌到内耳膜充满后，将双手突然放开，同时鼻喷气，使气到气窍，两眼、两耳、口腔、两鼻孔，九次。<br>
<br>
功能：七窍通畅，气血流通，平衡机体，给大脑加压，加强五官功能锻炼，增强对外界不适气候的免疫力，预防感冒，清醒头脑，治疗鼻炎等鼻部疾病。<br>
<br>
第三式：划太阳。用中指中冲穴，以鼻部两眉中心部，经印堂，划至太阳穴点压，力度适中，九次。<br>
<br>
功能：对头晕脑胀、头痛有特效，能消除疲劳，使血液循环和神经功能得到正常调节。<br>
<br>
第四式：拉耳。将双掌根用力挤压耳部，不留一丝缝隙。然后猛然拉开，能有开啤酒瓶一样的&ldquo;砰&rdquo;声，反复九次。<br>
<br>
功能：对防止耳聋，增强听力，治疗耳鸣和中耳炎，激发、开发小脑，使骨髓充足，产生很好的功效。如拉耳时，耳部里面有隐痛，说明耳有潜在的病因，坚持做。<br>
<br>
第五式：梳顶。十指如耙，如梳头状从前发际梳到后发根，路线：以前头的&ldquo;上星穴&rdquo;到头顶的&ldquo;百会穴&rdquo;，从后脑&ldquo;风府穴&rdquo;；到大椎。然后左右梳顶，前后左右各九次。<br>
<br>
功能：头为诸阳之会，百会升举清阳，使百脉调和，改善头部末梢血液循环，既能疏散过多充血现象，又助防止脑溢血，还可改善大脑供血、乌发、黑发、发根脱落，并有助任督气血经络通畅，能去风，稳血压，调阴阳，平衡机体，活跃大脑生理功能，消除疲劳，提高大脑工作效率，增强记忆力。<br>
<br>
第六式：拍头。双手掌用力适度，由轻到重，由慢到快，交替拍打头顶正中，头正身直，下颌内收，体验拍头的力度颤动全身，反复36次。<br>
<br>
功能：类似第五式，能改善大脑供血，调整阴阳，疏通经络，活跃大脑生理机能。拍打时仔细体验全身颤抖。<br>
<br>
第七式：叩脑。两掌心紧按耳孔，两手指的十宣穴（十指头）轮击头枕骨，能听到&ldquo;咚咚咚咚&rdquo;的声音，也叫&ldquo;鸣天鼓&rdquo;，反复36次。<br>
<br>
功能：改善对脑的血液供给，锻炼听觉，预防耳疾，按摩小脑，使脑精气充足，提神醒脑。<br>
<br>
第八式：摩大椎。大椎&mdash;&mdash;在颈椎和胸椎连接处，双掌举手脑后，重叠压于颈部，两大拇指反复点按揉动大椎穴，用力适中，反复36次。<br>
<br>
功能：大椎为诸阳交汇的地方，对它的刺激，可直接调动全身元阳，对防止感冒、颈椎病、风寒、通经活血等有很好的疗效，同时能锻炼颈项之力，使血液循环和神经功能得到正常调节，改善心脏与大脑的供血通道，从而达到头脑清醒，血压稳定之功效。<br>
<br>
收式：接第八式摩大椎，双手分两颈由前胸从上至下贴身收于小腹丹田，双掌重叠（男左手在内，女右手在内）放于小腹处，收腹提肛。意想真气收归丹田，不再启动。时间1至3分钟左右。<br>
<br>
第九式：浴手。以右手空心拳从颈部沿左肩与手臂内侧向下拍打至手掌，再从手背沿外侧拍打至肩峰，反复旋回九遍。然后换手，以左手拍打右手，反复九遍。<br>
<br>
功能：对疏通手三阴和手三阳的经络有较好的效果，并能祛除手部关节炎、风湿等病症。<br>
<br>
第十式：浴身。以双手空心拳沿胸骨两侧向下拍打，在胸口正部膻中穴交汇，再沿肋弓向两侧拍打，直至小腹丹田。力度适中，反复九遍。<br>
<br>
功能：对增强五脏六腑机能，祛除风湿疾病有很好效果。亦是武术健身的基本功。<br>
<br>
第十一式：浴腿。以双手空心拳，从小腹丹田沿环腰带脉拍打至命门穴。再沿双腿外侧向下拍打至外踝；再从内踝，沿双腿内侧向上拍打回丹田。反复九遍。<br>
<br>
功能：对疏通腿部经络（足三阴、足三阳经），治疗风湿、关节炎有疗效。<br>
<br>
第十二式：浴腰。以两手掌捂住腰部肾区，约一分钟，然后用掌根部由内向外旋转揉压按摩三十六次，再反揉三十六次。<br>
<br>
功能：增强肾功能、消除腰肌劳损、治疗风湿均有疗效。<br>
<br>
第十三次：浴背。双脚约宽于肩，双手自然下垂放松，扭动腰部，双手摆动，以空心掌自然拍打对侧肩臂及背心部。由轻渐重，由慢渐快，反复三十六次。<br>
<br>
功能：增强抗击能力，利于周身气血旺盛，对背部、肩周炎及手部疾病有较好疗效，对肾功能增强有较好的促进作用。<br>
<br>
第十四式：浴丹田。接上式，动作与十三式类同，双手以空心掌同时前后拍打腹部丹田和后腰部命门穴三十六次。由轻渐重，由慢渐快。<br>
<br>
功能：增强抗击能力，利于全身气血旺盛，对背部、肩部、腰部均有疗效和健身效果。<br>
<br>
第十五式：悬照。全身自然放松，双脚与肩同宽，保持预备姿式，曲膝，双手掌心、掌背分别悬空照于丹田和命门处，前手掌心遥对小腹丹田，后手掌背遥对后腰命门，掌心、掌背距丹田、命门约10cm左右。体会良性意识，意想光辉照穿、照透、照亮整个腰腹部。双手在中途交换1次。时间共约3分钟。<br>
<br>
功能：调节人体阴阳平衡、增长体力。<br>
<br>
第十六式：收式。双腿收拢并立，双手贴身收置于小腹丹田处，双掌重叠（男左手在内、女右手左内），掌心向内。持续用力收小腹提肛。意想全身真气收归丹田，不再启动。时间1 至3分钟左右。<br>
<br>
作用：聚气、固肾。并对排泄系统疾病、便秘及妇科疾病有特效</font></span></p>
</div>
<div> </div>
<div> </div>
<div><span><span><font size="5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  道友分享---太一站<font color="#000000">樁 </font></font></span></span></div>
<div> </div>
<div><span><span><font size="5">(网 <span><span><span><font style="font-size: 16px"><font size="5">址：<a href="http://you.video.sina.com.cn/b/20606519-1442720673.html"><font color="#ae0405" size="2">http://you.video.sina.com.cn/b/20606519-1442720673.html</font></a></font></font></span></span></span></font></span></span><span><span><font size="5">)</font></span></span></div>
</div> <a href="http://hi.baidu.com/zcsong85/blog/item/fc97175162207c2e42a75bd8.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/zcsong85/blog/category/%C8%CB%C9%FA">人生</a>&nbsp;<a href="http://hi.baidu.com/zcsong85/blog/item/fc97175162207c2e42a75bd8.html#comment">查看评论</a>]]></description>
        <pubDate>2009-10-25  10:24</pubDate>
        <category><![CDATA[人生]]></category>
        <author><![CDATA[zcsong85]]></author>
		<guid>http://hi.baidu.com/zcsong85/blog/item/fc97175162207c2e42a75bd8.html</guid>
</item>

<item>
        <title><![CDATA[句句讽刺，句句经典zz]]></title>
        <link><![CDATA[http://hi.baidu.com/zcsong85/blog/item/b750ac1f55e323c1a7866936.html]]></link>
        <description><![CDATA[
		
		<div style="display: block; margin-left: 10px" class="l"><a title="转帖" href=" :showRepasteDlg( 0 ,  repaste_6137109_4948476-540643115-3 , 6137109 );"></a></div>
<div class="c"> </div>
<div style="margin-top: 10px; width: 550px; margin-bottom: 20px; margin-left: 15px" class="f14">
<p> </p>
<p><strong><span style="color: rgb(180,80,200)"><span>1.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>别在我的坟前哭，脏了我轮回的路。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>2.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>我这人从不记仇</span><span style="color: rgb(180,80,200)">,</span></strong><strong><span>一般有仇当场我就报了。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>3.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>是这样的张总，你在家里的电脑上按了</span><span style="color: rgb(180,80,200)">CTRL+C</span></strong><strong><span>，然后在公司的电脑上再按</span><span style="color: rgb(180,80,200)">CTRL+V</span></strong><strong><span>是肯定不行的。即使同一篇文章也不行。不不，多贵的电脑都不行。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>4.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>你要是鲜花，以后牛都不敢拉粪了！</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>5.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>自己选择</span><span style="color: rgb(180,80,200)">45°</span></strong><strong><span>仰视别人，就休怪他人</span><span style="color: rgb(180,80,200)">135°</span></strong><strong><span>俯视着看你。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>6.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>我爸面对我发胖一事发表了看法：没有韩红的命，还得了韩红的病。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>7.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>现在你骂我，是因为你还不了解我，等你以后了解了我，你一定会动手打我的。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>8.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>过往的人啊</span><span style="color: rgb(180,80,200)"> </span></strong><strong><span>不要为我的死悲伤</span><span style="color: rgb(180,80,200)"> </span></strong><strong><span>如果我活着</span><span style="color: rgb(180,80,200)"> </span></strong><strong><span>你们谁也活不了</span><span style="color: rgb(180,80,200)">――――-</span></strong><strong><span>罗伯斯庇尔墓志铭</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>9.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span style="color: rgb(180,80,200)">&ldquo;</span></strong><strong><span>你喜欢我天使的脸孔，还是魔鬼的身材？</span><span style="color: rgb(180,80,200)">&rdquo;&ldquo;</span></strong><strong><span>我就喜欢你这种幽默感。</span><span style="color: rgb(180,80,200)">&rdquo; </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>10.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>广播体操现在开始：</span><span style="color: rgb(180,80,200)">╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗╔</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╝╚</span></strong><strong><span>囧</span><span style="color: rgb(180,80,200)">╗ </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>11.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span style="color: rgb(180,80,200)"> &ldquo;</span></strong><strong><span>恋</span><span style="color: rgb(180,80,200)">&rdquo;</span></strong><strong><span>是个很强悍的字。它的上半部取自</span><span style="color: rgb(180,80,200)">&ldquo;</span></strong><strong><span>变态</span><span style="color: rgb(180,80,200)">&rdquo;</span></strong><strong><span>的</span><span style="color: rgb(180,80,200)">&ldquo;</span></strong><strong><span>变</span><span style="color: rgb(180,80,200)">&rdquo;</span></strong><strong><span>，下半部取自</span><span style="color: rgb(180,80,200)">&ldquo;</span></strong><strong><span>变态</span><span style="color: rgb(180,80,200)">&rdquo;</span></strong><strong><span>的</span><span style="color: rgb(180,80,200)">&ldquo;</span></strong><strong><span>态</span><span style="color: rgb(180,80,200)">&rdquo;</span></strong><strong><span>。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>12.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>这姑娘，穿的是真清凉，长的是真败火。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>13.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>求最悲伤的歌？最佳答案：《社会主义好》</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>14.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>到一寺庙，一得道高僧讲：施主捐些款吧，三百五百的都行。回答说：实在没带这么多钱，下次吧。高僧回答：可以刷卡。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>15.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>我能抵抗一切，除了诱惑</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>16.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>别人都说我长得天生励志！</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>17.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>人干点好事总想让神鬼知道，干点坏事总以为神鬼不知道，我们太难为神鬼了</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>18.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>真不好意思，让您贱笑了。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>19.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>骗子太多，傻子明显不够用了</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>20.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>初中的体育老师说：谁敢再穿裙子上我的课，就罚她倒立。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>21.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>每个成功的奥特曼背后都有一个默默挨打的小怪兽。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>22.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>好的爱情是你透过一个男人看到世界，坏的爱情是你为了一个人舍弃世界。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>23.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>人不能把钱带进坟墓，但钱却可以把人带进去</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>24.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>这世界上最遥远的距离，不是天涯海角，也不是生死别离，而是我身在祖国，却不知道祖国在发生什么。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>25.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>时间是最好的老师，但遗憾的是</span><span style="color: rgb(180,80,200)">&mdash;&mdash;</span></strong><strong><span>最后他把所有的学生都弄死了。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>26.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>《绝望的主妇》第一集就有这样的台词：</span><span style="color: rgb(180,80,200)">&ldquo;</span></strong><strong><span>男人勃</span><span style="color: rgb(180,80,200)">(</span></strong><strong><span>绿坝</span><span style="color: rgb(180,80,200)">)</span></strong><strong><span>起的时候是没有道德可言的。</span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>27.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>城市里除了性无能的男人，就是爱无能的男人，除了这两者，只剩下，女人。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>28.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>一个人的死是一个悲剧</span><span style="color: rgb(180,80,200)"> </span></strong><strong><span>千百万人的死却仅仅是个统计数字</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>29.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>有的人，从他看电影的方式就能看出他人品，看文艺片时不断快进，看</span><span style="color: rgb(180,80,200)">A(</span></strong><strong><span>绿坝</span><span style="color: rgb(180,80,200)">)</span></strong><strong><span>片时不断暂停。</span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>30.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>一分钟有多长？这要看你是蹲在厕所里面，还是等在厕所外面</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>31.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>我们最大的情敌，不是第三者，而是岁月</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>32.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>我最想做你的一颗牙齿</span><span style="color: rgb(180,80,200)">. </span></strong><strong><span>因为这样</span><span style="color: rgb(180,80,200)">.</span></strong><strong><span>至少</span><span style="color: rgb(180,80,200)"> </span></strong><strong><span>你没有我的时候</span><span style="color: rgb(180,80,200)">.</span></strong><strong><span>你会疼</span><span style="color: rgb(180,80,200)">. </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>33.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>一北京人叹道：北京的地铁真挤，上周一孕妇被挤流产了。上海人不削的说：上海的地铁才叫挤，去年一少女被挤怀孕了。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>34.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>就算是一坨屎，也有遇见屎壳郎的那天。所以你大可不必为今天的自己有太多担忧。</span><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"> </span></strong></p>
<p><strong><span style="color: rgb(180,80,200)"><span>35.<span>&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span></strong><strong><span>人又不聪明，还学别人秃顶</span></strong></p>
</div> <a href="http://hi.baidu.com/zcsong85/blog/item/b750ac1f55e323c1a7866936.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/zcsong85/blog/category/%C9%FA%BB%EE">生活</a>&nbsp;<a href="http://hi.baidu.com/zcsong85/blog/item/b750ac1f55e323c1a7866936.html#comment">查看评论</a>]]></description>
        <pubDate>2009-09-05  13:34</pubDate>
        <category><![CDATA[生活]]></category>
        <author><![CDATA[zcsong85]]></author>
		<guid>http://hi.baidu.com/zcsong85/blog/item/b750ac1f55e323c1a7866936.html</guid>
</item>

<item>
        <title><![CDATA[3 mistakes to avoid when using jQuery with ASP.NET AJAX(zz)]]></title>
        <link><![CDATA[http://hi.baidu.com/zcsong85/blog/item/6cda3e457283452fcffca337.html]]></link>
        <description><![CDATA[
		
		<span class="post-calendar">By <strong>Dave Ward</strong> on June 5th, 2008</span>
<div class="post-content">
<p>Over the past few weeks, I think I have definitely embodied <strong>Jeff Atwood</strong>’s claim that <a href="http://www.codinghorror.com/blog/archives/001124.html">we’re all amateurs, learning together</a>.  Despite my best efforts to thoroughly test before posting, a few problems slipped through in my recent posts about <a href="http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/">using jQuery to consume ASP.NET JSON serialized web services</a> and <a href="http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/">using jQuery to call ASP.NET AJAX page methods</a>.</p>
<p>On the bright side, your great feedback in both posts’ comments has reinforced the fact that some of <strong>the best content on my blog is the part that you write</strong>.</p>
<p>In this post, I’m going to detail three of the problems that were discovered as a result of those previous two posts:</p>
<ul>
    <li>An extra requirement when making a read-only request to IIS6+.</li>
    <li>An oddity in Internet Explorer 7’s XmlHttpRequest class.</li>
    <li>A common mistake when passing JSON parameters through jQuery.</li>
</ul>
<p>Finally, I’ll suggest what I now believe to be a best practice usage, taking all of these issues into account.</p>
<p> </p>
<h3>Security requirements when POSTing to IIS</h3>
<p>This error message was the most common problem that was reported:</p>
<blockquote>
<p>Length Required</p>
</blockquote>
<p>The underlying issue is that most installations of IIS6+ require a content-length be provided with all POST requests, <strong>even if there is no content</strong> (POST data).</p>
<p>The content-length for a request with no data should be 0, but jQuery doesn’t set that header automatically unless there is a data parameter. Since ASP.NET AJAX’s JSON serialized services require a POST request, this becomes a stumbling block for read-only requests.</p>
<p>The easiest way I’ve found to work around this is to use an empty JSON object as a parameter on read-only requests. For example, if you were calling a page method:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript">$.<span style="color: rgb(102, 0, 102);">ajax</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">{</span><br>  type<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;POST&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  url<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;PageMethod.aspx/PageMethodName&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  data<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;{}&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  contentType<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;application/json; charset=utf-8&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  dataType<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;json&quot;</span><br><span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p>This will cause jQuery to correctly set a content-length of 2, while your web service or page method will happily ignore the empty parameter and treat the request as read-only.</p>
<p>You might notice the content-type is set differently in this example than in my previous posts.  More on that next:</p>
<h3>A problem with Internet Explorer and XmlHttpRequest</h3>
<p>Previously, to call ASP.NET AJAX services with jQuery, I suggested this usage:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript">$.<span style="color: rgb(102, 0, 102);">ajax</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">{</span><br>  type<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;POST&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  url<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;WebService.asmx/WebMethodName&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  beforeSend<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span>xhr<span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span><br>    xhr.<span style="color: rgb(102, 0, 102);">setRequestHeader</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(51, 102, 204);">&quot;Content-type&quot;</span><span style="color: rgb(51, 153, 51);">,</span> <br>                         <span style="color: rgb(51, 102, 204);">&quot;application/json; charset=utf-8&quot;</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span><br>  <span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(51, 153, 51);">,</span><br>  dataType<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;json&quot;</span><br><span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p>The reason for the beforeSend delegate is due a quirk in jQuery which causes it to send a specified content-type <em>only if there is also a data parameter specified</em>.</p>
<p><a target="_new" href="http://weblogs.asp.net/scottgu/archive/2007/04/04/json-hijacking-and-how-asp-net-ajax-1-0-mitigates-these-attacks.aspx">For security reasons</a>, ASP.NET AJAX will not provide a JSON serialized response unless the proper content-type is provided. By using the beforeSend delegate as shown, the content-type will be manually set on the XmlHttpRequest object, before the request.</p>
<p>However, the new XmlHttpRequest class in Internet Explorer 7 doesn’t implement <strong>set</strong>RequestHeader very intuitively.  Instead of <strong>setting</strong> the specified header, it <strong>appends</strong> the value.</p>
<p>This becomes a problem when you make a request that includes a data parameter. When POST data is provided, jQuery will automatically set the content-type to its default of <em>application/x-www-form-urlencoded</em>.  In the beforeSend delegate, the required <em>application/json; charset=utf-8</em> will be <strong>appended after</strong> jQuery’s default.</p>
<p>End result? Because this amalgamation of content-types isn’t what ASP.NET AJAX expects, the web service will not return JSON serialized content and jQuery will be unable to parse it.</p>
<p>Solution?  If you’re sending data in your request, <strong>use jQuery’s contentType parameter</strong> to set the content-type, so that the default is never added:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript">$.<span style="color: rgb(102, 0, 102);">ajax</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">{</span><br>  type<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;POST&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  url<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;WebService.asmx/WebMethodName&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  data<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;{'fname':'dave', 'lname':'ward'}&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  contentType<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;application/json; charset=utf-8&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  dataType<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;json&quot;</span><br><span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<h3>JSON, objects, and strings: oh my!</h3>
<p>In requests made to them, ASP.NET AJAX script services and page methods understand and expect parameters serialized as JSON strings. These parameters are parsed out of the POST data and used as arguments to the method you’ve called.</p>
<p>However, if you directly provide a JSON object as the data parameter for an $.ajax call, jQuery will attempt to serialize the object instead of passing it on to your web service.</p>
<p>Take this sample request, for example:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript">$.<span style="color: rgb(102, 0, 102);">ajax</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">{</span><br>  type<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;POST&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  url<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;WebService.asmx/WebMethodName&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  data<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 153, 0);">{</span><span style="color: rgb(51, 102, 204);">'fname'</span><span style="color: rgb(51, 153, 51);">:</span><span style="color: rgb(51, 102, 204);">'dave'</span><span style="color: rgb(51, 153, 51);">,</span> <span style="color: rgb(51, 102, 204);">'lname'</span><span style="color: rgb(51, 153, 51);">:</span><span style="color: rgb(51, 102, 204);">'ward'</span><span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(51, 153, 51);">,</span><br>  contentType<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;application/json; charset=utf-8&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  dataType<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;json&quot;</span><br><span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p>Because that data parameter is a valid JSON object, calling the web service this way won’t throw any errors. Unfortunately, it won’t have the desired result either. Instead of passing that JSON object through to the web service, jQuery will automatically serialize and send it as:</p>
<blockquote>
<p>fname=dave&amp;lname=ward</p>
</blockquote>
<p>To which, the server will respond with:</p>
<blockquote>
<p>Invalid JSON primitive: fname.</p>
</blockquote>
<p>This is clearly not what we want to happen.  The solution is to make sure that you’re passing jQuery a <strong>string</strong> for the data parameter, like this:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript">$.<span style="color: rgb(102, 0, 102);">ajax</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">{</span><br>  type<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;POST&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  url<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;WebService.asmx/WebMethodName&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  data<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;{'fname':'dave', 'lname':'ward'}&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  contentType<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;application/json; charset=utf-8&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  dataType<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;json&quot;</span><br><span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p>It’s a small change in syntax, but makes all the difference. Now, jQuery will leave our JSON object alone and pass the entire string to ASP.NET for parsing on the server side.</p>
<h3>Best practice?  I hope so this time!</h3>
<p>Taking these three caveats into account, I think this is the best practice for calling <strong>read-only</strong> ASP.NET AJAX web services via jQuery:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript">$.<span style="color: rgb(102, 0, 102);">ajax</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">{</span><br>  type<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;POST&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  url<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;ServiceName.asmx/WebMethodName&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  data<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;{}&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  contentType<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;application/json; charset=utf-8&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  dataType<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;json&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  success<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span>msg<span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span><br>    <span style="color: rgb(0, 102, 0); font-style: italic;">// Do interesting things here.</span><br>  <span style="color: rgb(0, 153, 0);">}</span><br><span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p>When consuming web services that require parameters, the usage is similar. Just make sure that you’re passing a JSON object in a <strong>string</strong>:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript">$.<span style="color: rgb(102, 0, 102);">ajax</span><span style="color: rgb(0, 153, 0);">(</span><span style="color: rgb(0, 153, 0);">{</span><br>  type<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;POST&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  url<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;ServiceName.asmx/WebMethodName&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  data<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;{'fname':'dave','lname':'ward'}&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  contentType<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;application/json; charset=utf-8&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  dataType<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(51, 102, 204);">&quot;json&quot;</span><span style="color: rgb(51, 153, 51);">,</span><br>  success<span style="color: rgb(51, 153, 51);">:</span> <span style="color: rgb(0, 51, 102); font-weight: bold;">function</span><span style="color: rgb(0, 153, 0);">(</span>msg<span style="color: rgb(0, 153, 0);">)</span> <span style="color: rgb(0, 153, 0);">{</span><br>    <span style="color: rgb(0, 102, 0); font-style: italic;">// Do magic here.</span><br>  <span style="color: rgb(0, 153, 0);">}</span><br><span style="color: rgb(0, 153, 0);">}</span><span style="color: rgb(0, 153, 0);">)</span><span style="color: rgb(51, 153, 51);">;</span></pre>
</div>
</div>
<p>In either of these cases, substitute PageName.aspx for ServiceName.asmx and PageMethodName for WebMethodName if you want to call a page method instead of a web service.</p>
<h3>Conclusion</h3>
<p>I hope this post will help you to avoid these common problems when using <strong>jQuery</strong> with <strong>ASP.NET AJAX</strong>.  I think there’s a great synergy between the two that is certainly worth jumping through these few hoops.</p>
<p>I’d especially like to thank <strong>Martin</strong> and <strong>Ryan</strong> for their invaluable feedback, leading to two of the three solutions posted above.</p>
<p>If you’ve run into related problems yourself, I’m eager to hear about them. Please don’t hesitate to comment if you think I’m still missing something important.</p>
</div>
<div >
<h3>Possibly related posts</h3>
<ul class="ul-archives">
    <li><a title="March 27, 2008" rel="bookmark" href="http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/">Using jQuery to Consume ASP.NET JSON Web Services</a></li>
    <li><a title="July 21, 2009" rel="bookmark" href="http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/">Simplify calling ASP.NET AJAX services from jQuery</a></li>
    <li><a title="June 29, 2009" rel="bookmark" href="http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/">Never worry about ASP.NET AJAX’s .d again</a></li>
    <li><a title="April 7, 2009" rel="bookmark" href="http://encosia.com/2009/04/07/using-complex-types-to-make-calling-services-less-complex/">Using complex types to make calling services less… complex</a></li>
    <li><a title="May 29, 2008" rel="bookmark" href="http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/">Using jQuery to directly call ASP.NET AJAX page methods</a></li>
</ul>
</div>
<div >
<h3>Share this post</h3>
<div ><a rel="nofollow" href="http://www.dotnetkicks.com/kick/?url=http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/"><img width="82" height="18" border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/" alt="kick it on DotNetKicks.com"></a></div>
<div >


  </div>
</div>
<div >
<h3>What do you think?  Your comments are welcomed.</h3>
<p>I appreciate all of your comments, questions, and other feedback, but please try to stay on topic.  If you have a question               unrelated to this post, I recommend posting on the <a target="_blank" rel="nofollow" href="http://forums.asp.net/">ASP.NET forums</a> or               <a target="_blank" rel="nofollow" href="http://stackoverflow.com/">Stack Overflow</a> instead.</p>
<p>If you're replying to an existing comment, please use the threading feature.  To do this, click the               &quot;Reply to this comment&quot; link underneath the comment you're replying to.</p>
</div>

<h3 >Other sites linking to this post</h3>
<div >
<ol>
    <li><a class="url" rel="external nofollow" href="http://www.alvinashcraft.com/2008/06/05/dew-drop-june-5-2008/">Dew Drop – June 5, 2008 | Alvin Ashcraft's Morning Dew</a></li>
    <li><a class="url" rel="external nofollow" href="http://weblogs.asp.net/yuanjian/archive/2008/06/05/interesting-finds-2008-06-06.aspx">Interesting Finds: 2008.06.06 - gOODiDEA.NET</a></li>
    <li><a class="url" rel="external nofollow" href="http://www.allcoolblogs.com/blog/2008/06/06/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/">3 mistakes to avoid when using jQuery with ASP.NET AJAX</a></li>
    <li><a class="url" rel="external nofollow" href="http://www.pathf.com/blogs/2008/06/pitfalls-of-using-jquery-with-aspnet-ajax/">Pathfinder Development &#187; Pitfalls of Using JQuery with ASP.NET Ajax</a></li>
    <li><a class="url" rel="external nofollow" href="http://jamazon.co.uk/web/2008/06/09/tips-for-using-jquery-with-aspnet-ajax/">Jamie Thompson &#187; Tips for Using JQuery with ASP.NET Ajax</a></li>
    <li><a class="url" rel="external nofollow" href="http://code-inside.de/blog/2008/06/09/wchentliche-rundablage-silverlight-2-wpf-aspnet-mvc-jquery/">W&#246;chentliche Rundablage: Silverlight 2, WPF, ASP.NET MVC, jQuery… | Code-Inside Blog</a></li>
    <li><a class="url" rel="external nofollow" href="http://code-inside.de/blog-in/2008/06/09/wchentliche-rundablage-silverlight-2-wpf-aspnet-mvc-jquery/">Weekly Links: Silverlight 2, WPF, ASP.NET MVC, jQuery… | Code-Inside Blog International</a></li>
    <li><a class="url" rel="external nofollow" href="http://blogger.forgottenskies.com/?p=114">More jQuery with Ajax/Json : { null != Steve }</a></li>
    <li><a class="url" rel="external nofollow" href="http://blog.playgroundsunshine.com/?p=20">Playground Sunshine &#187; Blog Archive &#187; jQuery Flexigrid with ASP.NET webservice and ADO.NET Entity Framework Part 1</a></li>
    <li><a class="url" rel="external nofollow" href="http://dotnetslackers.com/Community/blogs/xun/archive/2008/10/15/good-links-asp-net-and-jquery.aspx">Good links: ASP .NET and JQuery - Programmatically Speaking ...</a></li>
    <li><a class="url" rel="external nofollow" href="http://vincenthomedev.wordpress.com/2008/05/30/using-jquery-to-consume-aspnet/">Using jQuery to Consume ASP.NET 2.0 &#171; vincenthome’s Tech Clips</a></li>
    <li><a class="url" rel="external nofollow" href="http://goneale.wordpress.com/2009/01/27/submitting-an-ajax-form-with-aspnet-mvc-jquery/">Submitting an AJAX Form with ASP.NET MVC + jQuery &#171; {Programming} &amp; Life</a></li>
    <li><a class="url" rel="external nofollow" href="http://peterskim.org/2009/04/13/jquery-and-asp-net-mvc-browser-issues/">jQuery and ASP .NET MVC: browser issues | peterskim</a></li>
</ol>
</div> <a href="http://hi.baidu.com/zcsong85/blog/item/6cda3e457283452fcffca337.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/zcsong85/blog/category/web%BF%AA%B7%A2">web开发</a>&nbsp;<a href="http://hi.baidu.com/zcsong85/blog/item/6cda3e457283452fcffca337.html#comment">查看评论</a>]]></description>
        <pubDate>2009-08-21  08:24</pubDate>
        <category><![CDATA[web开发]]></category>
        <author><![CDATA[zcsong85]]></author>
		<guid>http://hi.baidu.com/zcsong85/blog/item/6cda3e457283452fcffca337.html</guid>
</item>

<item>
        <title><![CDATA[SQL Server 中当前持有的所有锁的信息]]></title>
        <link><![CDATA[http://hi.baidu.com/zcsong85/blog/item/26950ed643d8322607088bb4.html]]></link>
        <description><![CDATA[
		
		下面的示例显示 &#160; SQL &#160; Server &#160; 中当前持有的所有锁的信息。 &#160; <br>
<br>
USE &#160; master &#160; <br>
EXEC &#160; sp_lock &#160; <br>
<br>
其中&quot;类型&quot;列显示当前锁定的资源类型。 &#160; <br>
<br>
资源类型 &#160; 描述 &#160;  &#160; <br>
RID &#160; 用于锁定表中的一行的行标识符。 &#160;  &#160; <br>
KEY &#160; 索引中的行锁。用于保护可串行事务中的键范围。 &#160;  &#160; <br>
PAG &#160; 数据或索引页。 &#160;  &#160; <br>
EXT &#160; 相邻的八个数据页或索引页构成的一组。 &#160;  &#160; <br>
TAB &#160; 包括所有数据和索引在内的整个表。 &#160;  &#160; <br>
DB &#160; 数据库。 &#160;  &#160; <br>
<br>
<br>
如何查看当前锁（企业管理器） &#160; <br>
<br>
展开服务器组，然后展开服务器。 &#160; <br>
<br>
<br>
展开&quot;管理&quot;，然后展开&quot;当前活动&quot;。 &#160; <br>
<br>
<br>
执行下列操作中的一种： &#160;  &#160; <br>
展开&quot;锁/进程 &#160; ID&quot;以查看每个连接的当前锁。 &#160; <br>
<br>
<br>
展开&quot;锁/对象&quot;以查看每个对象的当前锁。 &#160;  &#160; <br>
在控制台树中单击要查看的连接 &#160; (SPID) &#160; 或对象。 &#160;  &#160; <br>
该连接或对象的当前锁显示在详细信息窗格中。 &#160; <br>
<br>
SQL &#160; Server &#160; 使用以下资源锁模式。 &#160; <br>
<br>
锁模式 &#160; 描述 &#160;  &#160; <br>
共享 &#160; (S) &#160; 用于不更改或不更新数据的操作（只读操作），如 &#160; SELECT &#160; 语句。 &#160;  &#160; <br>
更新 &#160; (U) &#160; 用于可更新的资源中。防止当多个会话在读取、锁定以及随后可能进行的资源更新时发生常见形式的死锁。 &#160;  &#160; <br>
排它 &#160; (X) &#160; 用于数据修改操作，例如 &#160; INSERT、UPDATE &#160; 或 &#160; DELETE。确保不会同时对同一资源进行多重更新。 &#160;  &#160; <br>
意向 &#160; 用于建立锁的层次结构。意向锁的类型为：意向共享 &#160; (IS)、意向排它 &#160; (IX) &#160; 以及与意向排它共享 &#160; (SIX)。 &#160;  &#160; <br>
架构 &#160; 在执行依赖于表架构的操作时使用。架构锁的类型为：架构修改 &#160; (Sch-M) &#160; 和架构稳定性 &#160; (Sch-S)。 &#160;  &#160;  &#160; <br>
大容量更新 &#160; (BU) &#160; 向表中大容量复制数据并指定了 &#160; TABLOCK &#160; 提示时使用。 &#160;  &#160; <br>
<br>
虽然 &#160; Microsoft&amp;reg; &#160; SQL &#160; Server&amp;#8482; &#160; 2000 &#160; 自动执行锁定，但它仍可以通过以下方法自定义应用程序中的锁定： &#160;  &#160; <br>
<br>
处理死锁和设置死锁优先级。 &#160; <br>
<br>
处理超时和设置锁超时持续时间。 &#160; <br>
<br>
设置事务隔离级别。 &#160; <br>
<br>
对 &#160; SELECT、INSERT、UPDATE &#160; 和 &#160; DELETE &#160; 语句使用表级锁定提示。 &#160; <br>
<br>
配置索引的锁定粒度。 &#160;  &#160; <br>
<br>
<br>
可以使用 &#160; SELECT、INSERT、UPDATE &#160; 和 &#160; DELETE &#160; 语句指定表级锁定提示的范围，以引导 &#160; Microsoft&amp;reg; &#160; SQL &#160; Server&amp;#8482; &#160; 2000 &#160; 使用所需的锁类型。当需 &#160; <br>
<br>
要对对象所获得锁类型进行更精细控制时，可以使用表级锁定提示。这些锁定提示取代了会话的当前事务隔离级别。 &#160; <br>
<br>
说明 &#160;  &#160; SQL &#160; Server &#160; 查询优化器自动作出正确的决定。建议仅在必要时才使用表级锁定提示更改默认的锁定行为。禁止锁定级别反过来会影响并发 &#160; <br>
<br>
。 &#160; <br>
<br>
锁定提示 &#160; 描述 &#160;  &#160; <br>
HOLDLOCK &#160; 将共享锁保留到事务完成，而不是在相应的表、行或数据页不再需要时就立即释放锁。HOLDLOCK &#160; 等同于 &#160; SERIALIZABLE。 &#160;  &#160; <br>
NOLOCK &#160; 不要发出共享锁，并且不要提供排它锁。当此选项生效时，可能会读取未提交的事务或一组在读取中间回滚的页面。有可能发生脏读。仅 &#160; <br>
<br>
应用于 &#160; SELECT &#160; 语句。 &#160;  &#160; <br>
PAGLOCK &#160; 在通常使用单个表锁的地方采用页锁。 &#160;  &#160; <br>
READCOMMITTED &#160; 用与运行在提交读隔离级别的事务相同的锁语义执行扫描。默认情况下，SQL &#160; Server &#160; 2000 &#160; 在此隔离级别上操作。 &#160;  &#160; <br>
READPAST &#160; 跳过锁定行。此选项导致事务跳过由其它事务锁定的行（这些行平常会显示在结果集内），而不是阻塞该事务，使其等待其它事务释放 &#160; <br>
<br>
在这些行上的锁。READPAST &#160; 锁提示仅适用于运行在提交读隔离级别的事务，并且只在行级锁之后读取。仅适用于 &#160; SELECT &#160; 语句。 &#160;  &#160; <br>
READUNCOMMITTED &#160; 等同于 &#160; NOLOCK。 &#160;  &#160; <br>
REPEATABLEREAD &#160; 用与运行在可重复读隔离级别的事务相同的锁语义执行扫描。 &#160;  &#160;  &#160; <br>
ROWLOCK &#160; 使用行级锁，而不使用粒度更粗的页级锁和表级锁。 &#160;  &#160; <br>
SERIALIZABLE &#160; 用与运行在可串行读隔离级别的事务相同的锁语义执行扫描。等同于 &#160; HOLDLOCK。 &#160;  &#160; <br>
TABLOCK &#160; 使用表锁代替粒度更细的行级锁或页级锁。在语句结束前，SQL &#160; Server &#160; 一直持有该锁。但是，如果同时指定 &#160; HOLDLOCK，那么在事务结束 &#160; <br>
<br>
之前，锁将被一直持有。 &#160;  &#160; <br>
TABLOCKX &#160; 使用表的排它锁。该锁可以防止其它事务读取或更新表，并在语句或事务结束前一直持有。 &#160;  &#160; <br>
UPDLOCK &#160; 读取表时使用更新锁，而不使用共享锁，并将锁一直保留到语句或事务的结束。UPDLOCK &#160; 的优点是允许您读取数据（不阻塞其它事务）并 &#160; <br>
<br>
在以后更新数据，同时确保自从上次读取数据后数据没有被更改。 &#160;  &#160; <br>
XLOCK &#160; 使用排它锁并一直保持到由语句处理的所有数据上的事务结束时。可以使用 &#160; PAGLOCK &#160; 或 &#160; TABLOCK &#160; 指定该锁，这种情况下排它锁适用于适当 &#160; <br>
<br>
级别的粒度。 &#160;  &#160; <br>
<br>
<br>
例如，如果将事务隔离级别设置为 &#160; SERIALIZABLE，并且在 &#160; SELECT &#160; 语句中使用表级锁定提示 &#160; NOLOCK，则键范围锁通常用于维护不采用可串行事务 &#160; <br>
<br>
。 &#160; <br>
USE &#160; pubs &#160; <br>
GO &#160; <br>
SET &#160; TRANSACTION &#160; ISOLATION &#160; LEVEL &#160; SERIALIZABLE &#160; <br>
GO &#160; <br>
BEGIN &#160; TRANSACTION &#160; <br>
SELECT &#160; au_lname &#160; FROM &#160; authors &#160; WITH &#160; (NOLOCK) &#160; <br>
GO &#160; <a href="http://hi.baidu.com/zcsong85/blog/item/26950ed643d8322607088bb4.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/zcsong85/blog/category/%CA%FD%BE%DD%BF%E2">数据库</a>&nbsp;<a href="http://hi.baidu.com/zcsong85/blog/item/26950ed643d8322607088bb4.html#comment">查看评论</a>]]></description>
        <pubDate>2009-08-12  11:38</pubDate>
        <category><![CDATA[数据库]]></category>
        <author><![CDATA[zcsong85]]></author>
		<guid>http://hi.baidu.com/zcsong85/blog/item/26950ed643d8322607088bb4.html</guid>
</item>

<item>
        <title><![CDATA[How to Minimize SQL Server Blocking]]></title>
        <link><![CDATA[http://hi.baidu.com/zcsong85/blog/item/e439ebd08c2b3d86a0ec9c35.html]]></link>
        <description><![CDATA[
		
		<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tbody>
        <tr>
            <td align="left" class="authandpub">By :  <a href="http://www.sql-server-performance.com/authors/bradm.aspx" >Brad McGehee</a><br>
            Nov 15, 2006</td>
            <td align="right"> </td>
        </tr>
    </tbody>
</table>
<br>
<p><font size="2"><strong><span style="color: rgb(51, 51, 51); ">Blocking occurs when one connection to SQL Server locks one or more records, and a second connection to SQL Server requires a conflicting lock type on the record or records locked by the first connection</span></strong><span style="color: rgb(51, 51, 51); ">. This causes the second connection to wait until the first connection releases its locks. By default, a connection will wait an unlimited amount of time for the blocking lock to go away. Blocking is not the same thing as a deadlock.</span></font></p>
<p><span style="color: rgb(51, 51, 51); "><font size="2">A certain amount of blocking is normal and unavoidable. Too much blocking can cause connections (representing applications and users) to wait extensive periods of time, hurting overall SQL Server performance. In the worst cases, blocking can escalate as more and more connections are waiting for locks to be released, creating extreme slowdowns. The goal should be to reduce blocking as much as possible.</font></span></p>
<p><span style="color: rgb(51, 51, 51); "><font size="2">Locks held by SELECT statements are only held as long as it takes to read the data, not the entire length of the transaction. On the other hand, locks held by INSERT, UPDATE, and DELETE statements are held until the entire transaction is complete. This is done in order to allow easy rollback of a transaction, if necessary.</font></span></p>
<p><span style="color: rgb(51, 51, 51); "><font size="2">Some causes of excessive blocking, and ways to help avoid blocking, include:</font></span></p>
<ul type="disc" style="margin-top: 0in;">
    <li style="margin: 10pt 0in 0pt; color: rgb(51, 51, 51);" class="MsoNormal"><span><font size="2">Long-running queries. Anytime a query of any type, whether it is a SELECT, INSERT, UPDATE, or DELETE, takes more than a few seconds to complete, blocking is likely. The obvious solution to this is to keep transactions as short as possible. There are many tips on this web site on how to help reduce transaction time, but some of them include optimize Transact-SQL code, optimize indexes, break long transactions into multiple, smaller transactions, avoiding cursors, etc. </font></span></li>
    <li style="margin: 10pt 0in 0pt; color: rgb(51, 51, 51);" class="MsoNormal"><span><font size="2">Canceling queries, but not rolling them back. If your application’s code allows a running query to be cancelled, it is important that the code also roll back the transaction. If this does not happen, locks held by the query will not be released, which means blocking can occur. </font></span></li>
    <li style="margin: 10pt 0in 0pt; color: rgb(51, 51, 51);" class="MsoNormal"><span><font size="2">Distributed client/server deadlock. No, this is not your typical deadlock that is handled automatically by SQL Server, but a very special situation that is not automatically resolved by SQL Server. <br>
    <br>
    Here is what can happen. Let's say that an application opens two connections to SQL Server. The application then asynchronously starts a transaction and sends a query through the first connection to SQL Server, waiting for results. The application then starts a second transaction and sends a query through the second connection to SQL Server, waiting for results. At some point, one of the queries from one of the connections will begin to return results, and the application will then begin to process them. <br>
    <br>
    As the application processes the results, at some point what could happen is that the remainder of the results become blocked by the query running from the other connection. In other words, the first query can not complete because it is being blocked by the second query. So in essence, this connection is blocked and cannot continue until the second query completes. But what happens is that the second query tries to return its results, but because the application is blocked (from the first query), its results cannot be processed. So this means that this query cannot complete, which means the block on the first query can never end, and a deadlock situation occurs. Neither connection will give up, so neither connection ever ends, and the deadlock situation never ends. <br>
    <br>
    SQL Server is unable to resolve this type of deadlock, so unless you want to write applications that hang forever, you can take these steps to prevent this unusual situation: 1) Add a query time-out for each of the queries, or 2) Add a lock time-out for each of the queries, or 3) Use a bound connection for the application. </font></span></li>
</ul>
<p><span style="color: rgb(51, 51, 51); "><font size="2">In many ways, the best way to avoid blocking is to write well-tuned applications that follow the tuning advice found on this website. [7.0, 2000, 2005] <em><span>Updated 4-17-2006</span></em></font></span></p>
<p style="margin: auto 0in;" class="asterisk"><span><font color="#000080"><font size="2">*****</font></font></span></p>
<p><span style="color: rgb(51, 51, 51); "><font size="2">By default, <strong><span>blocking locks do not time out</span></strong>. The waiting connection waits until the lock is released, and the block is over. If you like, you can set a lock time-out so that a connection does not wait indefinitely for the blocking lock to be released. This is accomplished using the LOCK_TIMEOUT setting.</font></span></p>
<p><span style="color: rgb(51, 51, 51); "><font size="2">When the LOCK_TIMEOUT setting is used to set a maximum amount of time that a connection can wait for a blocking lock to go away, the connection that has the lock and is causing the blocking problem is not affected, but the connection waiting for the block is halted, and receives an error message. When this happens, then error message 1222, &quot;Lock request time-out period exceeded&quot; is sent to the application.</font></span></p>
<p><span style="color: rgb(51, 51, 51); "><font size="2">This means that the application needs to include the appropriate error-handling code to deal with this situation and take the appropriate action, which includes rolling back the transaction. If the application does not know how to deal with this error message, and the transaction is not rolled back, it is possible that the application can continue as if the transaction was not automatically cancelled. Because of this, you should not use the LOCK-TIMEOUT setting unless your application(s) that will be affected by it know what to do when they receive this message from SQL Server.</font></span></p>
<p><span style="color: rgb(51, 51, 51); "><font size="2">The syntax for the SET LOCK_TIMEOUT is:</font></span></p>
<p style="margin: auto 0in;" class="textcode"><font face="Courier New"><font color="#0033ff"><font size="2">SET LOCK_TIMEOUT <em><span>timeout_period</span></em></font></font></font></p>
<p><span style="color: rgb(51, 51, 51); "><font size="2">Where <em><span>timeout_period</span></em> is the number of milliseconds that a connection waits for a blocking lock to go away before an error is returned from SQL Server to the application. A value of -1 is the default, which means to wait indefinitely. A value of 0 tells SQL Server not to wait at all, and to return the error immediately.</font></span></p>
<p><span style="color: rgb(51, 51, 51); "><font size="2">This command is based on a per connection basis, and stays with the connection until the connection is broken, or a new SET LOCK_TIMEOUT command is issued. [7.0, 2000] <em><span>Updated 4-17-2006</span></em></font></span></p>
<p style="margin: auto 0in;" class="asterisk"><span><font color="#000080"><font size="2">*****</font></font></span></p>
<p><font size="2"><strong><span style="color: rgb(51, 51, 51); ">Avoid INSERTing, UPDATEing, or DELETEing large numbers of records in a single transaction</span></strong><span style="color: rgb(51, 51, 51); ">. If you do, all the records affected by your action will be locked until the transaction is done. If you find that you need to perform mass data changes, it is better to batch them into smaller, shorter transactions to prevent unnecessary locking.</span></font></p>
<span style="color: rgb(51, 51, 51); "><font size="2">In addition, changing the backup method from full to simple will also reduce the overhead incurred by long running transactions. Once you are done with the long running activity, you can switch back to the full backup method. [6.5, 7.0, 2000] <em><span>Updated 4-17-2006</span></em></font></span> <a href="http://hi.baidu.com/zcsong85/blog/item/e439ebd08c2b3d86a0ec9c35.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/zcsong85/blog/category/%CA%FD%BE%DD%BF%E2">数据库</a>&nbsp;<a href="http://hi.baidu.com/zcsong85/blog/item/e439ebd08c2b3d86a0ec9c35.html#comment">查看评论</a>]]></description>
        <pubDate>2009-08-12  08:54</pubDate>
        <category><![CDATA[数据库]]></category>
        <author><![CDATA[zcsong85]]></author>
		<guid>http://hi.baidu.com/zcsong85/blog/item/e439ebd08c2b3d86a0ec9c35.html</guid>
</item>

<item>
        <title><![CDATA[IIS-Server is too busy(zz)]]></title>
        <link><![CDATA[http://hi.baidu.com/zcsong85/blog/item/209840177448cc00c93d6dfa.html]]></link>
        <description><![CDATA[
		
		httpRuntime Server Too Busy<br>
<br>
修改方法：修改服务器.net配置“machine.config＂文件，该文件位于Windows系统目录下，如“C:\WINDOWS \Microsoft.NET\Framework\v1.1.4322\CONFIG　”，视你的网盘程序版本，修改对应目录下的 machine.config文件，如2.0版本用户就修改“C:\WINDOWS\Microsoft.NET\Framework \v2.0.50727\CONFIG”下的machine.config文件，查找该文件中的“processModel”配置段落，修改其中的字段 maxWorkerThreads=&quot;200&quot; maxIoThreads=&quot;200&quot;，1.1和2.0的默认段落不太一样，修改后的配置如下：<br>
<br>
1.1版本：<br>
<br>
&lt;processModel<br>
enable=&quot;true&quot;<br>
timeout=&quot;Infinite&quot;<br>
idleTimeout=&quot;Infinite&quot;<br>
shutdownTimeout=&quot;0:00:05&quot;<br>
requestLimit=&quot;Infinite&quot;<br>
requestQueueLimit=&quot;5000&quot;<br>
restartQueueLimit=&quot;10&quot;<br>
memoryLimit=&quot;60&quot;<br>
webGarden=&quot;false&quot;<br>
cpuMask=&quot;0xffffffff&quot;<br>
userName=&quot;machine&quot;<br>
password=&quot;AutoGenerate&quot;<br>
logLevel=&quot;Errors&quot;<br>
clientConnectedCheck=&quot;0:00:05&quot;<br>
comAuthenticationLevel=&quot;Connect&quot;<br>
comImpersonationLevel=&quot;Impersonate&quot;<br>
responseDeadlockInterval=&quot;00:03:00&quot;<br>
maxWorkerThreads=&quot;200&quot;<br>
maxIoThreads=&quot;200&quot;<br>
/&gt;<br>
<br>
2.0版本：<br>
原来默认的是&lt;processModel autoConfig=&quot;true&quot;/&gt;<br>
<br>
改为&lt;processModel maxWorkerThreads=&quot;200&quot; maxIoThreads=&quot;200&quot;/&gt;<br>
<br>
不用重新启动服务器就可以看到效果。<br>
<br>
以上只是个人实践体会，我的服务器状态是：２００３操作系统，<br>
<br>
<br>
<br>
最近公司的一个ASP.NET站点频繁出现Server Too Busy错误，具体表现为页面响应慢、经常出现Server Too Busy异常；但实际上服务器的资源消耗却很低，CPU使用只有10%左右，非常奇怪。<br>
<br>
该站点运行环境为Windows 2000，IIS5.0，.NET Framework 1.1，站点压力约为每秒10个连接，峰值时约为30。<br>
<br>
从网上查找相关资料后，从表现出的情况来看（响应慢，抛出Server Too Busy异常），初步判断为同时连接过多引起的线程阻塞引起。修改web.config中的httpRuntime配置节中的appRequestQueueLimit参数后，Server Too Busy 的错误得到解决。此参数默认从machine.config中继承，默认值为100，改为1000后Server Too Busy的错误不再出现。<br>
<br>
虽然服务器忙的错误解决了，但是站点响应还是很慢，有时候要等上5—10秒才能打开页面。分析原因应该是同时请求过多，而IIS工作线程不足的原因引起，修改machine.config中processModel配置节maxWorkerThreads参数为200后站点响应速度慢的问题得到解决。此参数默认值为20，可根据服务器硬件配置于压力大小适当调整。<br>
<br>
分析原因，是因为站点程序中使用了HttpWebRequest请求外部服务器的页面，而这个操作是相当耗时的（外部服务器响应慢是主要原因）。当访问者的请求到达ASP.NET工作进程后，ASP.NET首先会检查是否有空余的工作线程（WorkerThread），如果有的话，就交给一个空闲的工作线程去处理，如果没有空闲的工作线程，那么这个请求就会被放到请求队列（RequestQueue）中，这个时候的表现就是响应很慢。当访问量过大导致请求队列也满了的时候，ASP.NET就会抛出Server Too Busy异常了。在.NET 1.1中，默认的工作线程和请求队列分别为20和100，当运行的代码比较费时而访问量又较大的时候，这两个默认值显然就太小了。（现在的服务器硬件便宜了，一般PC服务器的吞吐量都应该远超过这个数）。这两个值可以根据服务器压力大小来进行合理配置。以调整站点吞吐量。 <a href="http://hi.baidu.com/zcsong85/blog/item/209840177448cc00c93d6dfa.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/zcsong85/blog/category/web%BF%AA%B7%A2">web开发</a>&nbsp;<a href="http://hi.baidu.com/zcsong85/blog/item/209840177448cc00c93d6dfa.html#comment">查看评论</a>]]></description>
        <pubDate>2009-08-11  21:58</pubDate>
        <category><![CDATA[web开发]]></category>
        <author><![CDATA[zcsong85]]></author>
		<guid>http://hi.baidu.com/zcsong85/blog/item/209840177448cc00c93d6dfa.html</guid>
</item>

<item>
        <title><![CDATA[SqlServer 触发器 实例2（zz）]]></title>
        <link><![CDATA[http://hi.baidu.com/zcsong85/blog/item/bdedb38728aba223c75cc340.html]]></link>
        <description><![CDATA[
		
		<a href="../../zcsong85/blog/item/7a01c8348ff1a747241f1447.html" target="_blank"><strong><span style="font-size: 9pt; color: maroon;">INSTEAD OF</span></strong><strong><span style="font-size: 9pt; color: maroon;">触发器的工作过程</span></strong><span style="font-size: 9pt; color: black;"><br>
</span><span style="font-size: 9pt; color: black;">　　可以在表或视图上指定<span>INSTEAD OF</span>触发器。执行这种触发器就能够</span><span style="font-size: 9pt; color: red;">替代原始的触发动作</span><span style="font-size: 9pt; color: black;">。<span>INSTEAD OF</span>触发器</span><span style="font-size: 9pt; color: red;">扩展了视图更新的类型</span><span style="font-size: 9pt; color: black;">。对于每一种触发动作<span>(INSERT</span>、<span>UPDATE</span>或<span> DELETE)</span>，每一个表或视图</span><span style="font-size: 9pt; color: red;">只能有一个<span>INSTEAD OF</span>触发器</span><span style="font-size: 9pt; color: black;">。<span><br>
</span>　　<span>INSTEAD OF</span>触发器被用于更新那些没有办法通过正常方式更新的视图。例如，通常不能在一个基于连接的视图上进行<span>DELETE</span>操作。然而，可以编写一个<span>INSTEAD OF DELETE</span>触发器来实现删除。上述触发器可以访问那些如果视图是一个真正的表时已经被删除的数据行。将被删除的行存储在一个名为<span>deleted</span>的工作表中，就像<span>AFTER</span>触发器一样。相似地，在<span>UPDATE INSTEAD OF</span>触发器或者<span>INSERT INSTEAD OF</span>触发器中，你可以访问<span>inserted</span>表中的新行。<span><br>
<br>
</span>　　不能在带有<span>WITH CHECK OPTION</span>定义的视图中创建<span>INSTEAD OF</span>触发器。</span> </a>
<p align="left" class="MsoNormal" style="margin: 0cm 0cm 12pt; line-height: 18pt; text-align: left;"><strong><span style="font-size: 9pt; color: maroon;">示例</span></strong><span style="font-size: 9pt; color: black;"><br>
</span><span style="font-size: 9pt; color: black;">　　在本例中，创建了一个德国客户表和一个墨西哥客户表。放置在视图上的<span>INSTEAD OF</span>触发器将把更新操作重新定向到适当的基表上。这时发生的插入是对<span>CustomersGer</span>表的插入而不是对视图的插入。<span><br>
</span>　　创建两个包含客户数据的表：</span></p>
<p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; background: rgb(238, 238, 238) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; text-align: left;"><span style="font-size: 10pt;"><span style="color: blue;">SELECT</span><span style="color: black;"> </span><span style="color: gray;">*</span><span style="color: black;"> </span><span style="color: blue;">INTO</span><span style="color: black;"> CustomersGer </span><span style="color: blue;">FROM</span><span style="color: black;"> Customers </span><span style="color: blue;">WHERE</span><span style="color: black;"> Customers.Country </span><span style="color: gray;">=</span><span style="color: black;"> </span><span style="color: red;">'Germany'</span><span style="color: black;"><br>
</span><span style="color: blue;">SELECT</span><span style="color: black;"> </span><span style="color: gray;">*</span><span style="color: black;"> </span><span style="color: blue;">INTO</span><span style="color: black;"> CustomersMex </span><span style="color: blue;">FROM</span><span style="color: black;"> Customers </span><span style="color: blue;">WHERE</span><span style="color: black;"> Customers.Country </span><span style="color: gray;">=</span><span style="color: black;"> </span><span style="color: red;">'Mexico'</span><span style="color: black;"><br>
<br>
</span><span style="color: blue;">GO</span><span style="color: black;"><br>
</span></span></p>
<p align="left" class="MsoNormal" style="margin: 0cm 0cm 12pt; text-indent: 18pt; line-height: 18pt; text-align: left;"><span style="font-size: 9pt; color: black;">在该数据上创建视图：</span></p>
<p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; background: rgb(238, 238, 238) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; text-align: left;"><span style="font-size: 10pt;"><span style="color: blue;">CREATE</span><span style="color: black;"> </span><span style="color: blue;">VIEW</span><span style="color: black;"> CustomersView </span><span style="color: blue;">AS</span><span style="color: black;"><br>
</span><span style="color: blue;">SELECT</span><span style="color: black;"> </span><span style="color: gray;">*</span><span style="color: black;"> </span><span style="color: blue;">FROM</span><span style="color: black;"> CustomersGer<br>
</span><span style="color: blue;">UNION</span><span style="color: black;"><br>
</span><span style="color: blue;">SELECT</span><span style="color: black;"> </span><span style="color: gray;">*</span><span style="color: black;"> </span><span style="color: blue;">FROM</span><span style="color: black;"> CustomersMex<br>
</span><span style="color: blue;">GO</span><span style="color: black;"><br>
</span></span></p>
<p align="left" class="MsoNormal" style="margin: 0cm 0cm 12pt; text-indent: 18pt; line-height: 18pt; text-align: left;"><span style="font-size: 9pt; color: black;">创建一个在上述视图上的<span>INSTEAD OF</span>触发器：</span></p>
<p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; background: rgb(238, 238, 238) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; text-align: left;"><span style="font-size: 10pt;"><span style="color: blue;">CREATE</span><span style="color: black;"> </span><span style="color: blue;">TRIGGER</span><span style="color: black;"> Customers_Update2<br>
</span><span style="color: blue;">ON</span><span style="color: black;"> CustomersView<br>
INSTEAD </span><span style="color: blue;">OF</span><span style="color: black;"> </span><span style="color: blue;">UPDATE</span><span style="color: black;"> </span><span style="color: blue;">AS</span><span style="color: black;"><br>
</span><span style="color: blue;">DECLARE</span><span style="color: black;"> </span><span style="color: green;">@Country</span><span style="color: black;"> <strong>nvarchar</strong>(</span><strong><span style="color: maroon;">15</span></strong><span style="color: black;">)<br>
</span><span style="color: blue;">SET</span><span style="color: black;"> </span><span style="color: green;">@Country</span><span style="color: black;"> </span><span style="color: gray;">=</span><span style="color: black;"> (</span><span style="color: blue;">SELECT</span><span style="color: black;"> Country </span><span style="color: blue;">FROM</span><span style="color: black;"> Inserted)<br>
</span><span style="color: blue;">IF</span><span style="color: black;"> </span><span style="color: green;">@Country</span><span style="color: black;"> </span><span style="color: gray;">=</span><span style="color: black;"> </span><span style="color: red;">'Germany'</span><span style="color: black;"><br>
</span><span style="color: blue;">BEGIN</span><span style="color: black;"><br>
</span><span style="color: blue;">UPDATE</span><span style="color: black;"> CustomersGer<br>
</span><span style="color: blue;">SET</span><span style="color: black;"> CustomersGer.Phone </span><span style="color: gray;">=</span><span style="color: black;"> Inserted.Phone<br>
</span><span style="color: blue;">FROM</span><span style="color: black;"> CustomersGer </span><span style="color: blue;">JOIN</span><span style="color: black;"> Inserted<br>
</span><span style="color: blue;">ON</span><span style="color: black;"> CustomersGer.CustomerID </span><span style="color: gray;">=</span><span style="color: black;"> Inserted.CustomerID<br>
</span><span style="color: blue;">END</span><span style="color: black;"><br>
</span><span style="color: blue;">ELSE</span><span style="color: black;"><br>
</span><span style="color: blue;">IF</span><span style="color: black;"> </span><span style="color: green;">@Country</span><span style="color: black;"> </span><span style="color: gray;">=</span><span style="color: black;"> </span><span style="color: red;">'Mexico'</span><span style="color: black;"><br>
</span><span style="color: blue;">BEGIN</span><span style="color: black;"><br>
</span><span style="color: blue;">UPDATE</span><span style="color: black;"> CustomersMex<br>
</span><span style="color: blue;">SET</span><span style="color: black;"> CustomersMex.Phone </span><span style="color: gray;">=</span><span style="color: black;"> Inserted.Phone<br>
</span><span style="color: blue;">FROM</span><span style="color: black;"> CustomersMex </span><span style="color: blue;">JOIN</span><span style="color: black;"> Inserted<br>
</span><span style="color: blue;">ON</span><span style="color: black;"> CustomersMex.CustomerID </span><span style="color: gray;">=</span><span style="color: black;"> Inserted.CustomerID<br>
</span><span style="color: blue;">END</span><span style="color: black;"><br>
</span></span><span style="font-size: 9pt; color: black;"><br>
</span><span style="font-size: 9pt; color: black;">　　通过更新视图，测试触发器：</span></p>
<p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; background: rgb(238, 238, 238) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; text-align: left;"><span style="font-size: 10pt;"><span style="color: blue;">UPDATE</span><span style="color: black;"> CustomersView </span><span style="color: blue;">SET</span><span style="color: black;"> Phone </span><span style="color: gray;">=</span><span style="color: black;"> </span><span style="color: red;">' 030-007xxxx'</span><span style="color: black;"> <br>
</span><span style="color: blue;">WHERE</span><span style="color: black;"> CustomerID </span><span style="color: gray;">=</span><span style="color: black;"> </span><span style="color: red;">'ALFKI'</span><span style="color: black;"><br>
<br>
</span><span style="color: blue;">SELECT</span><span style="color: black;"> CustomerID, Phone </span><span style="color: blue;">FROM</span><span style="color: black;"> CustomersView <br>
</span><span style="color: blue;">WHERE</span><span style="color: black;"> CustomerID </span><span style="color: gray;">=</span><span style="color: black;"> </span><span style="color: red;">'ALFKI'</span><span style="color: black;"><br>
<br>
</span><span style="color: blue;">SELECT</span><span style="color: black;"> CustomerID, Phone </span><span style="color: blue;">FROM</span><span style="color: black;"> CustomersGer <br>
</span><span style="color: blue;">WHERE</span><span style="color: black;"> CustomerID </span><span style="color: gray;">=</span><span style="color: black;"> </span><span style="color: red;">'ALFKI'</span><span style="color: black;"><br>
</span></span></p>
<p align="left" class="MsoNormal" style="margin: 0cm 0cm 12pt; line-height: 18pt; text-align: left;"><span style="font-size: 9pt; color: black;"><br>
</span><span style="font-size: 9pt; color: black;">　　那么具体的讲，对于多列数据，如何计算方差呢？：</span></p>
<p align="left" class="MsoNormal" style="margin: 0cm 0cm 0pt; background: rgb(238, 238, 238) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; text-align: left;"><span style="font-size: 10pt;"><span style="color: blue;">CREATE</span><span style="color: black;"> </span><span style="color: blue;">TRIGGER</span><span style="color: black;"> </span><span style="color: red;">[calT1T2T3]</span><span style="color: black;"> </span><span style="color: blue;">ON</span><span style="color: black;"> dbo.DCLB <br>
</span><span style="color: blue;">FOR</span><span style="color: black;"> </span><span style="color: blue;">INSERT</span><span style="color: black;">,</span><span style="color: blue;">UPDATE</span><span style="color: black;"><br>
</span><span style="color: blue;">AS</span><span style="color: black;"><br>
</span><span style="color: blue;">update</span><span style="color: black;"> P<br>
</span><span style="color: blue;">SET</span><span style="color: black;"><br>
</span><span style="border: 1pt solid gray; padding: 0cm; background: white none repeat scroll 0% 0%; display: none; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">/**/</span><span style="color: teal;">/**/</span><span style="border: 1pt solid gray; padding: 0cm; background: white none repeat scroll 0% 0%; display: none; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;">/**/</span><span style="color: teal;">/*<br>
</span></span><span style="font-size: 10pt; color: teal;">计算方差的触发器<span><br>
*/</span></span><span style="font-size: 10pt; color: black;"><br>
P.T1</span><span style="font-size: 10pt; color: gray;">=</span><span style="font-size: 10pt; color: black;">(I.P1</span><span style="font-size: 10pt; color: gray;">+</span><span style="font-size: 10pt; color: black;">I.P2</span><span style="font-size: 10pt; color: gray;">+</span><span style="font-size: 10pt; color: black;">I.P3</span><span style="font-size: 10pt; color: gray;">+</span><span style="font-size: 10pt; color: black;">I.P4</span><span style="font-size: 10pt; color: gray;">+</span><span style="font-size: 10pt; color: black;">I.P5</span><span style="font-size: 10pt; color: gray;">+</span><span style="font-size: 10pt; color: black;">I.P6),<br>
P.T2</span><span style="font-size: 10pt; color: gray;">=</span><span style="font-size: 10pt; color: black;">(I.Y1</span><span style="font-size: 10pt; color: gray;">+</span><span style="font-size: 10pt; color: black;">I.Y2</span><span style="font-size: 10pt; color: gray;">+</span><span style="font-size: 10pt; color: black;">I.Y3</span><span style="font-size: 10pt; color: gray;">+</span><span style="font-size: 10pt; color: black;">I.Y4</span><span style="font-size: 10pt; color: gray;">+</span><span style="font-size: 10pt; color: black;">I.Y5</span><span style="font-size: 10pt; color: gray;">+</span><span style="font-size: 10pt; color: black;">I.Y6 ),x<br>
P.T3</span><span style="font-size: 10pt; color: gray;">=</span><span style="font-size: 10pt; color: fuchsia;">SQRT</span><span style="font-size: 10pt; color: black;">(P.T1</span><span style="font-size: 10pt; color: gray;">*</span><span style="font-size: 10pt; color: black;">P.T1</span><span style="font-size: 10pt; color: gray;">+</span><span style="font-size: 10pt; color: black;">P.T2</span><span style="font-size: 10pt; color: gray;">*</span><span style="font-size: 10pt; color: black;">P.T2)<br>
<br>
</span><span style="font-size: 10pt; color: blue;">FROM</span><span style="font-size: 10pt; color: black;"> DCLB </span><span style="font-size: 10pt; color: blue;">AS</span><span style="font-size: 10pt; color: black;"> P </span><span style="font-size: 10pt; color: blue;">INNER</span><span style="font-size: 10pt; color: black;"> </span><span style="font-size: 10pt; color: blue;">JOIN</span><span style="font-size: 10pt; color: black;"> Inserted </span><span style="font-size: 10pt; color: blue;">AS</span><span style="font-size: 10pt; color: black;"> I<br>
</span><span style="font-size: 10pt; color: blue;">ON</span><span style="font-size: 10pt; color: black;"> P.SID </span><span style="font-size: 10pt; color: gray;">=</span><span style="font-size: 10pt; color: black;"> I.SID<br>
</span></p>
<span style="font-size: 9pt; color: black;">　　触发器的使用很方便，而且也很简单，重要的是理解<span>inserted</span>过程。可将<span>UPDATE</span>语句看成两步操作：即捕获数据前像<span>(before image)</span>的<span>DELETE</span>语句，和捕获数据后像<span>(after image)</span>的<span>INSERT</span>语句。当在定义有触发器的表上执行<span>UPDATE</span>语句时，原始行（前像）被移入到<span>deleted</span>表，更新行（后像）被移入到<span>inserted</span>表。触发器检查<span>deleted</span>表和<span>inserted</span>表以及被更新的表，来确定是否更新了多行以及如何执行触发器动作。</span> <a href="http://hi.baidu.com/zcsong85/blog/item/bdedb38728aba223c75cc340.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/zcsong85/blog/category/%CA%FD%BE%DD%BF%E2">数据库</a>&nbsp;<a href="http://hi.baidu.com/zcsong85/blog/item/bdedb38728aba223c75cc340.html#comment">查看评论</a>]]></description>
        <pubDate>2009-08-05  15:33</pubDate>
        <category><![CDATA[数据库]]></category>
        <author><![CDATA[zcsong85]]></author>
		<guid>http://hi.baidu.com/zcsong85/blog/item/bdedb38728aba223c75cc340.html</guid>
</item>

<item>
        <title><![CDATA[SqlServer 触发器 实例1（zz）]]></title>
        <link><![CDATA[http://hi.baidu.com/zcsong85/blog/item/7a01c8348ff1a747241f1447.html]]></link>
        <description><![CDATA[
		
		<p align="left" style="margin: 0cm 0cm 12pt; line-height: 18pt; text-align: left;" class="MsoNormal"><font size="1"><span style="font-size: 9pt; color: black; ">可以定义一个无论何时用</span><span style="font-size: 9pt; color: red; ">INSERT</span><span style="font-size: 9pt; color: black; ">语句向表中插入数据时都会执行的触发器。<span><br>
</span>　　当触发<span>INSERT</span>触发器时，新的数据行就会被插入到触发器表和<span>inserted</span>表中。<span>inserted</span>表是一个逻辑表，它包含了已经</span><span style="font-size: 9pt; color: red; ">插入的数据行</span><span style="font-size: 9pt; color: black; ">的一个</span><span style="font-size: 9pt; color: red; ">副本</span><span style="font-size: 9pt; color: black; ">。<span>inserted</span>表包含了<span>INSERT</span>语句中已记录的插入动作。<span>inserted</span>表还允许引用由初始化<span>INSERT</span>语句而产生的日志数据。触发器通过检查<span>inserted</span>表来确定是否执行触发器动作或如何执行它。<span>inserted</span>表中的行总是触发器表中一行或多行的副本。<span><br>
</span>　　日志记录了所有修改数据的动作<span>(INSERT</span>、<span>UPDATE</span>和<span>DELETE</span>语句<span>)</span>，但在事务日志中的信息是不可读的。然而，<span>inserted</span>表允许你引用由<span>INSERT</span>语句引起的日志变化，这样就可以将插入数据与发生的变化进行比较，来验证它们或采取进一步的动作。也可以直接引用插入的数据，而不必将它们存储到变量中。<span><br>
</span>　</span><strong><span style="font-size: 9pt; color: maroon; ">　示例</span></strong><span style="font-size: 9pt; color: black; "><br>
</span><span style="font-size: 9pt; color: black; ">　　在本例中，将创建一个触发器。无论何时订购产品（无论何时向<span>Order Details</span>表中插入一条记录），这个触发器都将更新<span>Products</span>表中的一列<span>(UnitsInStock)</span>。用原来的值减去订购的数量值即为新值。<span></span></span></font></p>
<p align="left" style="margin: 0cm 0cm 0pt; background: rgb(238, 238, 238) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; text-align: left;" class="MsoNormal"><font size="1"><span style="font-size: 10pt; "><span style="color: blue;">USE</span><span style="color: black;"> Northwind<br>
</span><span style="color: blue;">CREATE</span><span style="color: black;"> </span><span style="color: blue;">TRIGGER</span><span style="color: black;"> OrdDet_Insert<br>
</span><span style="color: blue;">ON</span><span style="color: black;"> </span><span style="color: red;">[Order Details]</span><span style="color: black;"><br>
</span><span style="color: blue;">FOR</span><span style="color: black;"> </span><span style="color: blue;">INSERT</span><span style="color: black;"><br>
</span><span style="color: blue;">AS</span><span style="color: black;"><br>
</span><span style="color: blue;">UPDATE</span><span style="color: black;"> P </span><span style="color: blue;">SET</span><span style="color: black;"><br>
UnitsInStock </span><span style="color: gray;">=</span><span style="color: black;"> P.UnitsInStock &ndash; I.Quantity<br>
</span><span style="color: blue;">FROM</span><span style="color: black;"> Products </span><span style="color: blue;">AS</span><span style="color: black;"> P </span><span style="color: blue;">INNER</span><span style="color: black;"> </span><span style="color: blue;">JOIN</span><span style="color: black;"> Inserted </span><span style="color: blue;">AS</span><span style="color: black;"> I<br>
</span><span style="color: blue;">ON</span><span style="color: black;"> P.ProductID </span><span style="color: gray;">=</span><span style="color: black;"> I.ProductID<br>
</span></span></font></p>
<p align="left" style="margin: 0cm 0cm 12pt; text-indent: 18pt; line-height: 18pt; text-align: left;" class="MsoNormal"><font size="1"><strong><span style="font-size: 9pt; color: maroon; ">DELETE</span></strong><strong><span style="font-size: 9pt; color: maroon; ">触发器的工作过程</span></strong><span style="font-size: 9pt; color: black; "><br>
</span><span style="font-size: 9pt; color: black; ">　　当触发<span>DELETE</span>触发器后，从受影响的表中删除的行将被放置到一个特殊的<span>deleted</span>表中。<span>deleted</span>表是一个逻辑表，它保留已</span><span style="font-size: 9pt; color: red; ">被删除数据行</span><span style="font-size: 9pt; color: black; ">的一个</span><span style="font-size: 9pt; color: red; ">副本</span><span style="font-size: 9pt; color: black; ">。<span>deleted</span>表还允许引用由初始化<span>DELETE</span>语句产生的日志数据。<span><br>
</span>　　使用<span>DELETE</span>触发器时，需要</span><span style="font-size: 9pt; color: red; ">考虑以下的事项和原则</span><span style="font-size: 9pt; color: black; ">：<span><br>
</span>　　·当某行被添加到<span>deleted</span>表中时，它就不再存在于数据库表中；因此，<span>deleted</span>表和数据库表</span><span style="font-size: 9pt; color: red; ">没有相同的行。</span><span style="font-size: 9pt; color: black; "><br>
</span><span style="font-size: 9pt; color: black; ">　　·创建<span>deleted</span>表时，空间是从内存中分配的。<span>deleted</span>表总是</span><span style="font-size: 9pt; color: red; ">被存储在高速缓存</span><span style="font-size: 9pt; color: black; ">中。<span><br>
</span>　　·为<span>DELETE</span>动作定义的触发器并</span><span style="font-size: 9pt; color: red; ">不执行<span>TRUNCATE TABLE</span>语句</span><span style="font-size: 9pt; color: black; ">，原因在于日志不记录<span>TRUNCATE TABLE</span>语句。<span><br>
</span>　　</span><strong><span style="font-size: 9pt; color: maroon; ">示例</span></strong><span style="font-size: 9pt; color: black; "><br>
</span><span style="font-size: 9pt; color: black; ">　　在本例中，将创建一个触发器，无论何时删除一个产品类别（即从<span>Categories</span>表中删除一条记录），该触发器都会更新<span>Products</span>表中的<span>Discontinued</span>列。所有受影响的产品都标记为<span>1</span>，标示不再使用这些产品了。<span></span></span></font></p>
<p align="left" style="margin: 0cm 0cm 0pt; background: rgb(238, 238, 238) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; text-align: left;" class="MsoNormal"><font size="1"><span style="font-size: 10pt; "><span style="color: blue;">USE</span><span style="color: black;"> Northwind<br>
</span><span style="color: blue;">CREATE</span><span style="color: black;"> </span><span style="color: blue;">TRIGGER</span><span style="color: black;"> Category_Delete<br>
</span><span style="color: blue;">ON</span><span style="color: black;"> Categories<br>
</span><span style="color: blue;">FOR</span><span style="color: black;"> </span><span style="color: blue;">DELETE</span><span style="color: black;"><br>
</span><span style="color: blue;">AS</span><span style="color: black;"><br>
</span><span style="color: blue;">UPDATE</span><span style="color: black;"> P </span><span style="color: blue;">SET</span><span style="color: black;"> Discontinued </span><span style="color: gray;">=</span><span style="color: black;"> </span><strong><span style="color: maroon;">1</span></strong><span style="color: black;"><br>
</span><span style="color: blue;">FROM</span><span style="color: black;"> Products </span><span style="color: blue;">AS</span><span style="color: black;"> P </span><span style="color: blue;">INNER</span><span style="color: black;"> </span><span style="color: blue;">JOIN</span><span style="color: black;"> deleted </span><span style="color: blue;">AS</span><span style="color: black;"> d<br>
</span><span style="color: blue;">ON</span><span style="color: black;"> P.CategoryID </span><span style="color: gray;">=</span><span style="color: black;"> d.CategoryID</span></span></font></p>
<p align="left" style="margin: 0cm 0cm 12pt; line-height: 18pt; text-align: left;" class="MsoNormal"><font size="1"><span style="font-size: 9pt; color: black; "> </span></font></p>
<p align="left" style="margin: 0cm 0cm 12pt; line-height: 18pt; text-align: left;" class="MsoNormal"><font size="1"><strong><span style="font-size: 9pt; color: maroon; ">UPDATE</span></strong><strong><span style="font-size: 9pt; color: maroon; ">触发器的工作过程</span></strong><span style="font-size: 9pt; color: black; "><br>
</span><span style="font-size: 9pt; color: black; ">　　可将<span>UPDATE</span>语句看成两步操作：即捕获数据前像<span>(before image)</span>的<span>DELETE</span>语句，和捕获数据后像<span>(after image)</span>的<span>INSERT</span>语句。当在定义有触发器的表上执行<span>UPDATE</span>语句时，原始行（前像）被移入到<span>deleted</span>表，更新行（后像）被移入到<span>inserted</span>表。<span><br>
</span>　　触发器检查<span>deleted</span>表和<span>inserted</span>表以及被更新的表，来确定是否更新了多行以及如何执行触发器动作。<span><br>
</span>　　可以使用<span>IF UPDATE</span>语句定义一个监视指定列的数据更新的触发器。这样，就可以让触发器容易的隔离出特定列的活动。当它检测到指定列已经更新时，触发器就会进一步执行适当的动作，例如发出错误信息指出该列不能更新，或者根据新的更新的列值执行一系列的动作语句。<span><br>
</span>　　</span><strong><span style="font-size: 9pt; color: maroon; ">语法</span></strong></font></p>
<p align="left" style="margin: 0cm 0cm 0pt; background: rgb(238, 238, 238) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; text-align: left;" class="MsoNormal"><font size="1"><span style="font-size: 10pt; "><span style="color: blue;">IF</span><span style="color: black;"> </span><span style="color: blue;">UPDATE</span><span style="color: black;"> (</span><span style="color: gray;">&lt;</span><span style="color: black;">column_name</span><span style="color: gray;">&gt;</span><span style="color: black;">)</span></span></font></p>
<p align="left" style="margin: 0cm 0cm 12pt 51.75pt; text-indent: -33.75pt; line-height: 18pt; text-align: left;" class="MsoNormal"><font size="1"><span style="font-size: 9pt; color: maroon; "><span>例1<span style=" font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </span></span></span><span style="font-size: 9pt; color: maroon; ">本例阻止用户修改<span>Employees</span>表中的<span>EmployeeID</span>列。</span></font></p>
<p align="left" style="margin: 0cm 0cm 0pt; background: rgb(238, 238, 238) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; text-align: left;" class="MsoNormal"><font size="1"><span style="font-size: 10pt; "><span style="color: blue;">USE</span><span style="color: black;"> Northwind<br>
</span><span style="color: blue;">GO</span><span style="color: black;"><br>
</span><span style="color: blue;">CREATE</span><span style="color: black;"> </span><span style="color: blue;">TRIGGER</span><span style="color: black;"> Employee_Update<br>
</span><span style="color: blue;">ON</span><span style="color: black;"> Employees<br>
</span><span style="color: blue;">FOR</span><span style="color: black;"> </span><span style="color: blue;">UPDATE</span><span style="color: black;"><br>
</span><span style="color: blue;">AS</span><span style="color: black;"><br>
</span><span style="color: blue;">IF</span><span style="color: black;"> </span><span style="color: blue;">UPDATE</span><span style="color: black;"> (EmployeeID)<br>
</span><span style="color: blue;">BEGIN</span><span style="color: black;"> <br>
</span><span style="color: blue;">RAISERROR</span><span style="color: black;"> (</span><span style="color: red;">'Transaction cannot be processed.\<br>
***** Employee ID number cannot be modified.'</span><span style="color: black;">, </span><strong><span style="color: maroon;">10</span></strong><span style="color: black;">, </span><strong><span style="color: maroon;">1</span></strong><span style="color: black;">)<br>
</span><span style="color: blue;">ROLLBACK</span><span style="color: black;"> </span><span style="color: blue;">TRANSACTION</span><span style="color: black;"><br>
</span><span style="color: blue;">END</span><span style="color: black;"><br>
</span></span></font></p>
<p style="margin: 0cm 0cm 0pt;" class="MsoNormal"><font size="1"><span style="font-size: 9pt; color: black; ">　　</span></font></p> <a href="http://hi.baidu.com/zcsong85/blog/item/7a01c8348ff1a747241f1447.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/zcsong85/blog/category/%CA%FD%BE%DD%BF%E2">数据库</a>&nbsp;<a href="http://hi.baidu.com/zcsong85/blog/item/7a01c8348ff1a747241f1447.html#comment">查看评论</a>]]></description>
        <pubDate>2009-08-05  15:32</pubDate>
        <category><![CDATA[数据库]]></category>
        <author><![CDATA[zcsong85]]></author>
		<guid>http://hi.baidu.com/zcsong85/blog/item/7a01c8348ff1a747241f1447.html</guid>
</item>

<item>
        <title><![CDATA[SqlServer 触发器]]></title>
        <link><![CDATA[http://hi.baidu.com/zcsong85/blog/item/86f7b001c1c72f077aec2c45.html]]></link>
        <description><![CDATA[
		
		<font size="2">CREATE   TRIGGER   trigger_name      <br>
  ON   {   table   |   view   }      <br>
  [   WITH   ENCRYPTION   ]      <br>
  {   <br>
              {   {   FOR   |   AFTER   |   INSTEAD   OF   }   {   [   INSERT   ]   [   ,   ]   [   UPDATE   ]   }   <br>
                          [   WITH   APPEND   ]   <br>
                          [   NOT   FOR   REPLICATION   ]   <br>
                          AS   <br>
                          [   {   IF   UPDATE   (   column   )   <br>
                                      [   {   AND   |   OR   }   UPDATE   (   column   )   ]   <br>
                                                  [   ...n   ]   <br>
                          |   IF   (   COLUMNS_UPDATED   (   )   {   bitwise_operator   }   updated_bitmask   )   <br>
                                                  {   comparison_operator   }   column_bitmask   [   ...n   ]   <br>
                          }   ]      <br>
                          sql_statement   [   ...n   ]      <br>
              }      <br>
  }      <br>
     <br>
  参数   <br>
  trigger_name         <br>
  是触发器的名称。触发器名称必须符合标识符规则，并且在数据库中必须唯一。可以选择是否指定触发器所有者名称。         <br>
  Table   |   view         <br>
  是在其上执行触发器的表或视图，有时称为触发器表或触发器视图。可以选择是否指定表或视图的所有者名称。        <br>
  WITH   ENCRYPTION         <br>
  加密   syscomments   表中包含   CREATE   TRIGGER   语句文本的条目。使用   WITH   ENCRYPTION   可防止将触发器作为   SQL   Server   复制的一部分发布。   <br>
     <br>
  AFTER   <br>
     <br>
  指定触发器只有在触发   SQL   语句中指定的所有操作都已成功执行后才激发。所有的引用级联操作和约束检查也必须成功完成后，才能执行此触发器。         <br>
  如果仅指定   FOR   关键字，则   AFTER   是默认设置。         <br>
  不能在视图上定义   AFTER   触发器。   <br>
     <br>
  INSTEAD   OF   <br>
     <br>
  指定执行触发器而不是执行触发   SQL   语句，从而替代触发语句的操作。         <br>
  在表或视图上，每个   INSERT、UPDATE   或   DELETE   语句最多可以定义一个   INSTEAD   OF   触发器。然而，可以在每个具有   INSTEAD   OF   触发器的视图上定义视图。   <br>
     <br>
  INSTEAD   OF   触发器不能在   WITH   CHECK   OPTION   的可更新视图上定义。如果向指定了   WITH   CHECK   OPTION   选项的可更新视图添加   INSTEAD   OF   触发器，SQL   Server   将产生一个错误。用户必须用   ALTER   VIEW   删除该选项后才能定义   INSTEAD   OF   触发器。   <br>
     <br>
  {   [DELETE]   [,]   [INSERT]   [,]   [UPDATE]   }   <br>
     <br>
  是指定在表或视图上执行哪些数据修改语句时将激活触发器的关键字。必须至少指定一个选项。在触发器定义中允许使用以任意顺序组合的这些关键字。如果指定的选项多于一个，需用逗号分隔这些选项。   <br>
     <br>
  对于   INSTEAD   OF   触发器，不允许在具有   ON   DELETE   级联操作引用关系的表上使用   DELETE   选项。同样，也不允许在具有   ON   UPDATE   级联操作引用关系的表上使用   UPDATE   选项。   <br>
     <br>
  WITH   APPEND   <br>
     <br>
  指定应该添加现有类型的其它触发器。只有当兼容级别是   65   或更低时，才需要使用该可选子句。如果兼容级别是   70   或更高，则不必使用   WITH   APPEND   子句添加现有类型的其它触发器（这是兼容级别设置为   70   或更高的   CREATE   TRIGGER   的默认行为）。有关更多信息，请参见   sp_dbcmptlevel。   <br>
     <br>
  WITH   APPEND   不能与   INSTEAD   OF   触发器一起使用，或者，如果显式声明   AFTER   触发器，也不能使用该子句。只有当出于向后兼容而指定   FOR   时（没有   INSTEAD   OF   或   AFTER），才能使用   WITH   APPEND。以后的版本将不支持   WITH   APPEND   和   FOR（将被解释为   AFTER）。   <br>
     <br>
  NOT   FOR   REPLICATION   <br>
     <br>
  表示当复制进程更改触发器所涉及的表时，不应执行该触发器。   <br>
     <br>
  AS   <br>
     <br>
  是触发器要执行的操作。   <br>
     <br>
  sql_statement   <br>
     <br>
  是触发器的条件和操作。触发器条件指定其它准则，以确定   DELETE、INSERT   或   UPDATE   语句是否导致执行触发器操作。   <br>
     <br>
  当尝试   DELETE、INSERT   或   UPDATE   操作时，Transact-SQL语句中指定的触发器操作将生效。   <br>
     <br>
  触发器可以包含任意数量和种类的   Transact-SQL   语句。触发器旨在根据数据修改语句检查或更改数据；它不应将数据返回给用户。触发器中的   Transact-SQL   语句常常包含控制流语言。CREATE   TRIGGER   语句中使用几个特殊的表：     <br>
     <br>
  deleted   和   inserted   是逻辑（概念）表。这些表在结构上类似于定义触发器的表（也就是在其中尝试用户操作的表）；这些表用于保存用户操作可能更改的行的旧值或新值。例如，若要 检索   deleted   表中的所有值，请使用：     <br>
  SELECT   *   <br>
  FROM   deleted   <br>
     <br>
  如果兼容级别等于   70，那么在   DELETE、INSERT   或   UPDATE   触发器中，SQL   Server   将不允许引用   inserted   和   deleted   表中的   text、ntext   或   image   列。不能访问   inserted   和   deleted   表中的   text、ntext   和   image   值。若要在   INSERT   或   UPDATE   触发器中检索新值，请将   inserted   表与原始更新表联接。当兼容级别是   65   或更低时，对   inserted   或   deleted   表中允许空值的text、ntext   或   image   列，将返回空值；如果这些列不可为空，则返回零长度字符串。     <br>
  当兼容级别是   80   或更高时，SQL   Server   允许在表或视图上通过   INSTEAD   OF   触发器更新   text、ntext   或   image   列。   <br>
     <br>
  n   <br>
     <br>
  是表示触发器中可以包含多条   Transact-SQL   语句的占位符。对于   IF   UPDATE   (column)   语句，可以通过重复   UPDATE   (column)   子句包含多列。   <br>
     <br>
  IF   UPDATE   (column)   <br>
     <br>
  测试在指定的列上进行的   INSERT   或   UPDATE   操作，不能用于   DELETE   操作。可以指定多列。因为在   ON   子句中指定了表名，所以在   IF   UPDATE   子句中的列名前不要包含表名。若要测试在多个列上进行的   INSERT   或   UPDATE   操作，请在第一个操作后指定单独的   UPDATE(column)   子句。在   INSERT   操作中   IF   UPDATE   将返回   TRUE   值，因为这些列插入了显式值或隐性   (NULL)   值。    <br>
  说明      IF   UPDATE   (column)   子句的功能等同于   IF、IF...ELSE   或   WHILE   语句，并且可以使用   BEGIN...END   语句块。有关更多信息，请参见控制流语言。      <br>
  可以在触发器主体中的任意位置使用   UPDATE   (column)。   <br>
     <br>
  column   <br>
     <br>
  是要测试   INSERT   或   UPDATE   操作的列名。该列可以是   SQL   Server   支持的任何数据类型。但是，计算列不能用于该环境中。有关更多信息，请参见数据类型。      <br>
     <br>
  IF   (COLUMNS_UPDATED())      <br>
     <br>
  测试是否插入或更新了提及的列，仅用于   INSERT   或   UPDATE   触发器中。COLUMNS_UPDATED   返回   varbinary   位模式，表示插入或更新了表中的哪些列。   <br>
     <br>
  COLUMNS_UPDATED   函数以从左到右的顺序返回位，最左边的为最不重要的位。最左边的位表示表中的第一列；向右的下一位表示第二列，依此类推。如果在表上创建的触发器包含   8   列以上，则   COLUMNS_UPDATED   返回多个字节，最左边的为最不重要的字节。在   INSERT   操作中   COLUMNS_UPDATED   将对所有列返回   TRUE   值，因为这些列插入了显式值或隐性   (NULL)   值。   <br>
     <br>
  可以在触发器主体中的任意位置使用   COLUMNS_UPDATED。   <br>
     <br>
  bitwise_operator   <br>
     <br>
  是用于比较运算的位运算符。   <br>
     <br>
  updated_bitmask   <br>
     <br>
  是整型位掩码，表示实际更新或插入的列。例如，表   t1   包含列   C1、C2、C3、C4   和   C5。假定表   t1   上有   UPDATE   触发器，若要检查列   C2、C3   和   C4   是否都有更新，指定值   14；若要检查是否只有列   C2   有更新，指定值   2。   <br>
     <br>
  comparison_operator   <br>
     <br>
  是比较运算符。使用等号   (=)   检查   updated_bitmask   中指定的所有列是否都实际进行了更新。使用大于号   (&gt;)   检查   updated_bitmask   中指定的任一列或某些列是否已更新。   <br>
     <br>
  column_bitmask   <br>
     <br>
  是要检查的列的整型位掩码，用来检查是否已更新或插入了这些列。</font><br>
<br>
<br> <a href="http://hi.baidu.com/zcsong85/blog/item/86f7b001c1c72f077aec2c45.html">阅读全文</a>
		
		<br/><b>类别：</b><a href="http://hi.baidu.com/zcsong85/blog/category/%CA%FD%BE%DD%BF%E2">数据库</a>&nbsp;<a href="http://hi.baidu.com/zcsong85/blog/item/86f7b001c1c72f077aec2c45.html#comment">查看评论</a>]]></description>
        <pubDate>2009-08-05  15:29</pubDate>
        <category><![CDATA[数据库]]></category>
        <author><![CDATA[zcsong85]]></author>
		<guid>http://hi.baidu.com/zcsong85/blog/item/86f7b001c1c72f077aec2c45.html</guid>
</item>


</channel>
</rss>