中文翻译ADO NE.docx
- 文档编号:8394580
- 上传时间:2023-01-31
- 格式:DOCX
- 页数:11
- 大小:36.46KB
中文翻译ADO NE.docx
《中文翻译ADO NE.docx》由会员分享,可在线阅读,更多相关《中文翻译ADO NE.docx(11页珍藏版)》请在冰豆网上搜索。
中文翻译ADONE
附录二:
翻译
译文1:
ADO.NET1
大多数应用程序需要在同一的时间存取数据,当和应用程序工作在一起的时候ADO.NET成为一个至关重要的组件,数据存取使应用程序和储存全部数据的数据库联系在一起,不同的应用程序对数据库存取有着不同要求,VB.NET使用的是ADO.NET(ActiveXDataObject),因为它的数据存取和操作协议也能使我们的应用程序能够和网络工作在一起。
让我们看一下为什么ADO.NET会代替ADO。
ADO.NET的演变
第一个数据存模型DAO(dataaccessmodel)是为本地数据库创建的,它是由嵌入式引擎来执行其功能的。
之后是为客户服务器构架设计的RDO(RemoteDataObject)andADO(ActiveDataObject),但是没过多久ADO替代了RDO,ADO是一个很好的体系架构,但是随着语言和技术的改变,ADO开始不能适应了。
在ADO中,全部的数据被包含在一个recordset对象中,当在网络中执行和遇到敏锐的防火墙时就会出现问题,ADO是一个一直处于连接状态数据访问,这就意味着数据库连接一旦建立,这个连接就会一直处于连接状态直到应用程序关闭。
让连接在应用程序的生命周期一直开着会带来数据库的安全和网络堵塞的问题。
同时,因为要同时满足更多用户,数据库日益的变的重要。
现在我们开始考虑一个到数据库的连接的效率了。
打个比方,一个连接到数据库的应用程序可能比两个做的好,如果是十个那可能更差了。
假如连接达到一百个或超过一百个,那可能都不能用了。
同样,打开数据连接消耗最大限度的系统资源,会使系统的执行效率下降。
为什么要使用ADO.NET?
为了处理上面提到的毛病,ADO.NET诞生了。
它维持一个非连接的数据存取来解决上面的问题。
当应用程序连接数据库的时候,数据连接是打开的。
但是当请求一旦完成连接就关闭了。
同时,如一个数据库被更新了,连接将会保持足够长的时间来完成更新操作然后再关闭。
由于只是维持最小的限度周期的连接,ADO.NET节省了系统资源和提供了最大限度的数据库安全又没多大影响系统的性能。
同时,ADO.NET把数据转换成XML格式来执行相关的操作,这使得他们更有效率。
ADO.NET体系结构
在ADO.NET的数据存取依靠两个组件:
数据集(DataSet)和 数据提供者(DataProvider)数据集(DataSet)数据集是非连接的,用储存功能来表现数据。
它可以被认为是一部分相关数据的本地副本。
数据集驻留在内存中,它可以不依赖数据库被操作和更新。
当数据集被使用完毕后,改变可以被传回中央数据库来更新。
数据可以从任何的数据源被加载,像微软SQLserver数据库,Oracle数据库,或微软Access数据库。
数据供应者(DataProvider)
数据供应者负责提供和维持与数据库的连接。
一个数据供应者是一套工作在一起的组件,它能以有效的方式和性能驱动方式提供数据。
.NET框架现在带来了两个数据提供者:
SQL DataProvider是专门为微软SQLServer7.0设计的,而OleDbDataProvider允许我们连接到其他类型的数据库,像Access和Oracle。
每个数据提供者都由以下的组件类组成:
Connection对象提供连接到数据库。
Command对象执行命令。
DataAdapter对象用数据组装一个非连接的数据集和执行更新操作。
用ADO.NET存取数据可以概括如下:
一个连接对象为应用程序建立到数据库的连接,command对象提供直接对数据库的执行命令。
假如命令返回的值多于一个,command对象返回一个DataReader来提供数据。
做为选择,数据适配器可以被用来填充数据集对象。
数据库可以用command对象和适配器来更新。
组件类组成了数据提供者
Connection对象
Connection对象建立了到数据库的连接,MicrosoftVisualStudio.NET提供了两种类型的连接类。
一是SqlConnection对象,它是特别为连接MicrosoftSQLServer7.0而设计的。
二是OleDbConnection对象,它可以提供广泛的数据库连接类型,像微软Access和Oracle。
Connection对象包括全部连接到数据库的所需要的信息。
Command对象
Command对象由两种相应的类来描述:
SqlCommand和OleDbCommand。
Command对象用来直接执行通过数据连接到数据库的命令。
它也可以被用来执行数据库上的存储过程,SQL命令或直接返回一个完全的数据表。
Command对象提供三种方法来执行数据库上的命令:
ExecuteNonQuery:
执行没有返回值的命令,像插入、更行或删除。
ExecuteScalar:
通过数据库查询返回单个值。
ExecuteReader:
用DataReader的方法返回一个结果集。
DataReader对象
DataReader对象从数据库提供一个只向前移动、只读的、连接流数据记录集.不像其他数据提供者的组件。
DataReader对象不能直接实例化,而是通过执行Command对象的ExecuteReader方法返回DataReader实例。
SqlCommand对象的ExecuteReader方法返回一个SqlDataReader对象,OleDbCommand对象的ExecuteReader方法返回一个OleDbDataReader对象。
当你不需要在内存中缓存数据时,DataReader可以直接给应用逻辑提供数据行。
因为在内存中一次只允许缓存一行数据。
DataReader根据系统性能占用最少资源,但是在它的生命周期内却需要使用一个额外打开的Connection对象。
DataAdapter对象
DataAdapter是ADO.NET非连接数据存取的核心类,它的本质是数据库和数据集信息交流的中间媒介。
数据适配器使用它的填充方法同时给数据表和数据集填充数据。
当常驻内存的数据被操作之后,数据适配器调用更新方法来把改变提交给数据库。
它提供四种工具来描述数据库命令:
SelectCommand(选择命令)
InsertCommand(插入命令)
DeleteCommand(删除命令)
UpdateCommand(更新命令)
当更新命令被调用,数据集中的改变被复制回数据库,然后执行适当的插入命令、删除命令或更行命令。
原文1:
ADO.NET1
Mostapplicationsneeddataaccessatonepointoftimemakingitacrucialcomponentwhenworkingwithapplications.Dataaccessismakingtheapplicationinteractwithadatabase,whereallthedataisstored.Differentapplicationshavedifferentrequirementsfordatabaseaccess.VB.NETusesADO.NET(ActiveXDataObject)asit'sdataaccessandmanipulationprotocolwhichalsoenablesustoworkwithdataontheInternet.Let'stakealookwhyADO.NETcameintopicturereplacingADO.
EvolutionofADO.NET
Thefirstdataaccessmodel,DAO(dataaccessmodel)wascreatedforlocaldatabaseswiththebuilt-inJetenginewhichhadperformanceandfunctionalityissues.NextcameRDO(RemoteDataObject)andADO(ActiveDataObject)whichweredesignedforClientServerarchitecturesbutsoonADOtookoverRDO.ADOwasagoodarchitecturebutasthelanguagechangessoisthetechnology.WithADO,allthedataiscontainedinarecordsetobjectwhichhadproblemswhenimplementedonthenetwork andpenetratingfirewalls.ADOwasaconnecteddataaccess,whichmeansthatwhenaconnectiontothedatabaseisestablishedtheconnectionremainsopenuntiltheapplicationisclosed.Leavingtheconnectionopenforthelifetimeoftheapplication raisesconcernsaboutdatabasesecurityandnetworktraffic. Also,asdatabasesarebecomingincreasinglyimportantandastheyareservingmorepeople,aconnecteddataaccessmodelmakesusthinkaboutitsproductivity.Forexample,anapplicationwithconnecteddataaccessmaydowellwhenconnectedtotwoclients,thesamemaydopoorlywhenconnectedto10andmightbeunusablewhenconnectedto100ormore.Also,opendatabaseconnectionsusesystemresourcestoamaximumextentmakingthesystemperformancelesseffective.
WhyADO.NET?
Tocopeupwithsomeoftheproblemsmentionedabove,ADO.NETcameintoexistence.ADO.NETaddressestheabovementionedproblemsbymaintainingadisconnecteddatabaseaccessmodelwhichmeans, whenanapplicationinteractswiththedatabase,theconnectionisopenedtoservetherequestoftheapplicationandisclosedassoonastherequestiscompleted.Likewise,ifadatabaseisUpdated,theconnectionisopenedlongenoughtocompletetheUpdateoperationandisclosed.Bykeepingconnectionsopenforonlyaminimumperiodoftime,ADO.NETconservessystemresourcesandprovidesmaximumsecurityfordatabasesandalsohaslessimpactonsystemperformance.Also,ADO.NETwheninteractingwith thedatabaseusesXML andconvertsallthedataintoXMLformat fordatabaserelatedoperationsmakingthemmoreefficient.
TheADO.NETDataArchitecture
DataAccessinADO.NETreliesontwocomponents:
DataSetand DataProvider.
DataSet
Thedatasetisadisconnected,in-memoryrepresentationofdata.Itcanbeconsideredasalocalcopyof therelevantportionsofthedatabase.TheDataSetispersistedinmemoryandthedatainitcanbemanipulatedandupdatedindependentofthedatabase.WhentheuseofthisDataSetisfinished,changescanbemadebacktothecentraldatabaseforupdating.ThedatainDataSetcanbeloadedfromanyvaliddatasourcelikeMicrosoftSQLserverdatabase,anOracledatabaseorfromaMicrosoftAccessdatabase.
DataProvider
TheDataProviderisresponsibleforprovidingandmaintainingtheconnectiontothedatabase.ADataProviderisasetofrelatedcomponentsthatworktogethertoprovidedatainanefficientandperformancedrivenmanner.The.NETFrameworkcurrentlycomeswithtwoDataProviders:
theSQL DataProviderwhichisdesignedonlytoworkwithMicrosoft'sSQLServer7.0orlaterandtheOleDbDataProviderwhichallowsustoconnecttoothertypesofdatabaseslikeAccessandOracle.EachDataProviderconsistsofthefollowingcomponentclasses:
Theobjectwhichprovides aconnectiontothedatabase
TheCommandobjectwhichisusedtoexecuteacommand
TheDataReaderobjectwhichprovidesaforward-only,readonly,connectedrecordset
TheDataAdapterobjectwhichpopulatesadisconnectedDataSetwithdataandperformsupdate
DataaccesswithADO.NETcanbesummarizedasfollows:
Aconnectionobjectestablishestheconnectionfortheapplicationwiththedatabase.Thecommandobjectprovidesdirectexecutionofthecommandtothedatabase.Ifthecommandreturnsmorethanasinglevalue,thecommandobjectreturnsaDataReadertoprovidethedata.Alternatively,theDataAdaptercanbeusedtofilltheDatasetobject.ThedatabasecanbeupdatedusingthecommandobjectortheDataAdapter.
ComponentclassesthatmakeuptheDataProviders
TheConnectionObject
TheConnectionobjectcreatestheconnectiontothedatabase.MicrosoftVisualStudio.NETprovidestwotypesofConnectionclasses:
theSqlConnectionobject,whichisdesignedspecificallytoconnecttoMicrosoftSQLServer7.0orlater,andtheOleDbConnectionobject,whichcanprovideconnectionstoawiderangeofdatabasetypeslikeMicrosoftAccessandOracle.TheConnectionobjectcontainsalloftheinformationrequiredtoopenaconnectiontothedatabase.
TheCommandObject
TheCommandobjectisrepresentedbytwocorrespondingclasses:
SqlCommandandOleDbCommand.Commandobjectsareusedtoexecutecommandstoadatabaseacrossadataconnection.TheCommandobjectscanbeusedtoexecutestoredproceduresonthedatabase,SQLcommands,orreturncompletetablesdirectly.Commandobjectsprovidethreemethodsthatareusedtoexecutecommandsonthedatabase:
ExecuteNonQuery:
ExecutescommandsthathavenoreturnvaluessuchasINSERT,UPDATEorDELETE
ExecuteScalar:
Returnsasinglevaluefromadatabasequery
ExecuteReader:
ReturnsaresultsetbywayofaDataReaderobject
TheDataReaderObject
TheDataReaderobjectprovidesaforward-only,read-only,connectedstreamrecordsetfromadatabase.UnlikeothercomponentsoftheDataProvider,DataReaderobjectscannotbedirectlyinstantiated.Rather,theDataReaderisreturnedastheresultof theCommandobject'sExecuteReadermethod.TheSqlCommand.ExecuteReadermethodreturnsaSqlDataReaderobject,andtheOleDbCommand.ExecuteReadermethodreturnsanOleDbDataReaderobject.TheDataReadercanproviderowsofdatadirectlytoapplicationlogicwhenyoudonotneedtokeepthedatacachedinmemory.Becauseonlyonerowisinmemoryatatime,theDataReaderprovidesthelowestoverheadintermsofsystemperformancebutrequirestheexclusiveuseofanopenConnectionobjectforthelifetimeoftheDataReader.
TheDataAdapterObject
TheDataAdapteristheclassatthecoreofADO.NET'sdisconnecteddataaccess.ItisessentiallythemiddlemanfacilitatingallcommunicationbetweenthedatabaseandaDataSet.TheDataAdapterisusedeithertofillaDataTableorDataSetwithdatafromthedatabasewithit'sFillmethod.Afterthememory-residentdatahasbeenmanipulated,theDataAdaptercancommitthechangestothedatabasebycallingtheUpdatemethod.TheDataAdapterprovidesfourpropertiesthatrepresentdatabasecommands:
SelectCommand
InsertCommand
DeleteCommand
Update
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 中文翻译ADO NE 中文翻译 ADO