若相依 发表于 2015-1-16 22:53:37

ASP网页编程之在ASP数据库事件处置

楼上说交互性不好,太牵强了吧。在微软提供的一套框架中,利用asp做网站,开发效率高,使用人数少,减少不必要的开销。交互性是互动方式,是有开发人员决定的。事件处置|数据|数据库ASPTransactions

byChrisPayneIntroduction

Transactionsareimportanttomaintaindataintegrity,amongotherthings,andhavebeenusedwith
databasesforsometimenow.Luckily,transactionsarentrestrictedtodatabases-youcanusethemin
ActiveServerPagesaswell,andwithouthavingtocreatecustomcomponentsusingMicrosoftTransaction
Server(MTS).Thisarticlewilltakealookatwhattransactionsare,howtheywillhelpASPdevelopers,
andhowtoimplementthem.

WhatareTransactions?

Beforewediveintothemeat,wehavetounderstandtheterminology(believeme,Iwaslostforalong
timebecausenooneexplainedthesetermstome).

Basically,usingatransactionmeansitsanall-or-nonedeal.Nohalfways,nomaybes.Letssuppose
youremodifyingadatabase,andyouhavetoadd100newitems,oneatatime.Beforeaddingeachitem,
however,youhavetochecktomakesureitfitscertaincriteria-ifitdoesnt,thenyourdatabase
cries,youreceiveanerror,andtheprocessquits.Itmaynotbedesirabletoquithalfway-forwhatever
reason,youeitherwantallthenewrowsornoneofthem.

Entertransactions.Ifyouputtheprocessinatransaction,andifanerroroccurs,thetransaction
will"rollback"toastatejustbeforeyoustartedyourprocess.Thus,ifanyofthenewitemsdoesnt
meetthecriteria,noneofitemsgetsadded,insteadofonlythefirstfew.

Theclassicexampleisabankingapplication.Supposesomeonewantstotransferfundsfromoneaccountto
another.YouwoulddeductxamountfromaccountA,andthenaddittoaccountB.Supposeafteryouhave
deductedthemoneyfromaccountA(andbeforeyouaddittoaccountB),younoticeaproblem(perhaps
accountBhasrestrictions,orisnotavailableforsomereason).Iftheapplicationjustquitsherewith
someerrormessage,thenaccountAwillbeinanincorrectstate,meaningithasfundsmissing.These
fundsarenotinaccountByet,sotheyarejustfloatingoffincyberspace,andyouhaveoneveryunhappy
customer.Withtransactions,shouldyouencounterthiserror,theprocesswillrollbacktoaprevious
state,andthemoneywillautomaticallygobacktowhereitstarted.Iftherearenoproblems,however,
thetransactionwillcommit,andeverythingwillgothrough.

Anotherexamplemoreapropostowebdevelopmentisuserregistration.Supposeausercomestoyour
communitybuildingwebsiteanddecidestoregister.Oncetheysubmittheirinformation,youhavetoenter
itintoadatabase,andalsosetuptheirpersonalwebpage.Thus,everyuserinthedatabasemusthavea
personalwebpageaswell,ornoonewilleverknowthattheyarethere.YourASPscriptaddstheuser
intothedatabaseperfectly,butaservererrorcausesyourwebpagebuildingroutinetofail
unexpectedly.Younowhaveafloatinguser-auserinthedatabase,butwithoutawebpage.Ifthis
processweretransactional,youcouldrollbacktojustbeforeyouinsertedtheuserintothedatabase
(therebyeliminatingthefloatinguserproblem),andgracefullydisplayaniceerrormessagetotheuser.
Prettyslick,huh?

SoHowDoesitHelpMe?

Itsalwaysgottobeabout"me,"doesntit?Well,ifyoudidntgatheritfromabove,transactionsare
mainlyusedforerrorhandling.Theystopyoufromgettinginweirdpositionsthatyoucantgetoutofby
easilyallowingyoutoundothechangesyouvemade.Asyoudevelopmoreandmorecomplexweb
applications,theneedforstrongstateprotectionwillbecomeincreasinglynecessary.

WhatisMTS?

MTSisMicrosoftsanswertotransactions.Wewontgointotoomuchdetailhere,butMTSistheengine
thatkeepstrackofobjectstates,androllsthembackorcommitsthemwhennecessary.Eventhoughit
wontbeapparentinyourASPs,MTSisworkingbusilybehindthescenestokeeptrackofwhatyoure
doing.

MTSrequiresallobjectsthatusetransactionstoberegisteredinMTS.IISitselfhasmanydifferent
componentsthatprocesswebapplicationsthatareallregisteredwithMTS,whichiswhyASPscanrun
transactionallythroughMTS,invisibletotheuser(andsometimestothedeveloper).Sojusttrustuswhen
wesayyouneedMTS.

NOTE:ThoughMTSisinstalledwithWindowsNT,itusuallyisnotsetuptorunautomatically.Therefore,
beforerunninganyoftheexamplesbelow,makesuretheMTSservice(MSDTC)isrunning(intheservices
contr</p>想法是和程序员的想法不一样的.至于为什么.大家去想一想.跟心理学有关的

小女巫 发表于 2015-1-20 05:54:33

我想问如何掌握学习节奏(先学什么再学什么)最好详细点?

活着的死人 发表于 2015-1-28 10:27:54

如何更好的使自己的东西看上去很不错等等。其实这些都不是问题的实质,我们可以在实践中不断提升自己,不断充实自己。

冷月葬花魂 发表于 2015-2-12 06:08:25

作为IE上广为流传的动态网页开发技术,ASP以它简单易学博得了广大WEB程序爱好这的青睐,而且它对运行环境和开发品台的不挑剔,以及有大量有效的参考手册,极大的推广了它的发展。

乐观 发表于 2015-3-2 22:52:26

运用ASP可将VBscript、javascript等脚本语言嵌入到HTML中,便可快速完成网站的应用程序,无需编译,可在服务器端直接执行。容易编写,使用普通的文本编辑器编写,如记事本就可以完成。由脚本在服务器上而不是客户端运行,ASP所使用的脚本语言都在服务端上运行。

小妖女 发表于 2015-3-11 07:18:30

最近在学asp,不要问我为什么不直接学.net,因为公司网站是asp做的所以有这个需要,卖了本书asp入门到精通,对里面的六大内置对象老是记不住,还有很多属性和方法看的头晕。

蒙在股里 发表于 2015-3-17 23:08:55

尽管MS自己讲C#内核中更多的象VC,但实际上我还是认为它和Java更象一些吧。首先它是面向对象的编程语言,而不是一种脚本,所以它具有面向对象编程语言的一切特性,比如封装性、继承性、多态性等等,这就解决了刚才谈到的ASP的那些弱点。

只想知道 发表于 2015-3-25 06:17:38

ASP.Net摆脱了以前ASP使用脚本语言来编程的缺点,理论上可以使用任何编程语言包括C++,VB,JS等等,当然,最合适的编程语言还是MS为.NetFrmaework专门推出的C(读csharp),它可以看作是VC和Java的混合体吧。
页: [1]
查看完整版本: ASP网页编程之在ASP数据库事件处置