机械毕业设计英文外文翻译24Visual Studio .NET如何为并发控制生成SQL语句.docx

机械毕业设计英文外文翻译24Visual Studio .NET如何为并发控制生成SQL语句

收藏

压缩包内文档预览:
预览图 预览图 预览图 预览图 预览图 预览图 预览图 预览图 预览图 预览图 预览图 预览图 预览图 预览图 预览图 预览图 预览图 预览图 预览图 预览图
编号:553276    类型:共享资源    大小:26.19KB    格式:ZIP    上传时间:2015-12-04 上传人:QQ28****1120 IP属地:辽宁
6
积分
关 键 词:
机械毕业设计英文翻译文献翻译
资源描述:
机械毕业设计英文外文翻译24Visual Studio .NET如何为并发控制生成SQL语句,机械毕业设计英文翻译文献翻译
内容简介:
理学院毕业论文 第 1 页 /共 20 页 英文翻译 Visual Studio .NET 如何为并发控制生成 SQL 语句 翻译:翟靖轩 原作者: Steve Stein Visual Studio Team Microsoft Corporation 2002 年 2月 摘要 :这篇文章研究 Visual Studio .NET 为不同的并发控制 方式所 产生的 SQL 语句,如何对它们进行修改可以提高执行效率,以及如何生成不带并发控制的 SQL 语句。 目录 引言 阅读此文章时应具备的一些知识 生成的 SQL 语句在哪里 并发与数据适配器 (DataAdapter) 优化生成的 SQL 语句 并发与 CommandBuilder 对象 结论 引言 任何可能同时被多个用户访问或修改数据的应用程序,都需要进行并发控制。否则,一个用户更改记录时可能不经意的覆盖了其他用户 的更改 。 Visual Studio .NET 的设计工具可以生成 “保持所有值 ”方式 的开放式并发 SQL语句或生成 “最后的更新生效 ”方式的 SQL 语句来更新数据。这篇文章将解释: 不同的 SQL 语句是如何生成的 如何修改自动生成的 SQL 语句可以 提高执行效率 阅读此文章时应具备的一些知识 nts 理学院毕业论文 第 2 页 /共 20 页 你需要具备以下知识: 基本的 ADO.NET 概念,包括数据集 (DataSet)以及数据适配器 (DataAdapters)。更多信息请参见 ADO.NET 数据访问介绍 ( Introduction to Data Access with ADO.NET) 。 数据并发机制以及会操作 Visual Studio .NET。更多内容请参见 介绍 ADO.NET 中的数据并发 (Introduction to Data Concurrency in ADO.NET) 。 自动生成的 SQL 语句在哪里 自动生成的 SQL 语句在 command 对象的 CommandText 属性里 。 在 设 计 阶 段 配 置 DataAdapter 对 象 时 或 使 用CommandBuilder 对象时 SQL 命令被自动生成。更多信息,请参见 并发与 CommandBuilder 对象( Concurrency and Command Builder Objects) 。 配置 DataAdapter 对象 从工具箱的数据选项卡中拖一个 DataAdapter 对象 从服务器资源管理器拖一个数据表 选中已有的 DataAdapter 对象,然后单击在属性窗口底部的 “ 配置数据适配器 ” 链接 CommandBuilder 对象 CommandBuilder 对象在运行时刻被创建,更多信息请参阅 SqlCommandBuilder 或 OleDbCommandBuilder。 并发控制与数据适配器 (DataAdapter) 使用 “ 数据适配器 配置 向导 ” 配置数据适配器时,你可以选择是否使用开放式并发来生成 Update 和 Delete 语句。 一些思考和注意事项 你的数据源必须有一个主键才能以开放式并发方式生成SQL 语句 当使用从 “ 服务器资源管理器 ” 拖放一个数据表的方式来创建 DataAdapter 对象时, DataAdapter 对象自动生成基于开放式并发的 Update 和 Delete 语句。如果你不想使用开放式并发,右击 DataAdapter 对象, 从快捷菜单中选择 “配置nts 理学院毕业论文 第 3 页 /共 20 页 数据适配器 ”,然后 在“ 高级 SQL 生成选项 ” 对话框中清除“ 使用开放式并发 ” 选项 的选定 。向导则会重新创建不带并发检测的 SQL 语句。 当重新配置现有的 DataAdapter 时,应注意 “ 高级 SQL 生成选项” 对话框里的选项已经全部恢复默认。例如最初配置 DataAdapter 时没有 选定“ 使用开放式并发 ”选项 , 但是当 重新配置 DataAdapter 时, “使用 开放式并发 ” 选项却会被选定,即便你根本没有打开过 “ 高级 SQL 生成选项 ”对话框。 如果你在 “数据适配器配置 向导 ” 的“选择查询类型”页面 选择 “ 使用 现 有的存储过程 ” ,则 “使用开放式并发 ”选项将不可用。存储过程仍按其原来的方式执行。如果想使用并发检测的话,必须将其包括到存储过程中、或在你的应用程序中编写 相应的代码 。 当使用开放式并发来创建 SQL 命令时,不 会 对二进制 数据列验 证 进行 并发 处理 。 这将导致 用这种方法对大 的 二进制记录集执行按位比较算法时 的 效率低 下 。 用向导生成 SQL 语句 为了理解 Visual Studio .NET 如何使用开放式并发来生成 SQL语句,让我们来看看用 “ 数据适配器 配置 向导 ” 生成的 Update语句。我们将查看同一条语句在选择 “使用 开放式并发 ” 选项和不选择 “使用 开放式并发 ” 选项 时的 不同状态。 你会注意到,选择开放式并发与不选择开放式并发所生成 SQL语句的区别只 存 在于 Where 子句上。 注: 以下的例子使用 用“ 数据适配器 配置 向导 ” 生成的Update 语句,并 从 NorthWind 示例数据库的 Customers 表中选择了若干列。 使用开放式并发的 Update 语句 这个例子使用了 “ 数据适配器 配置 向导 ” 的默认 配置 ,即 选中了“ 使用开放式并发 ”选项 。 注 : 当使用开放式并发时,生成的 command 的参数集里还 存在 一个参数副本。第二个参数集(带 Original_前nts 理学院毕业论文 第 4 页 /共 20 页 缀的那个)保存了最初从数据源里读取的值。 检查 Where 子句发现,每一个生成的语句都要检测数据库当前的值是否等于最初读取的值(例, WHERE City = Original_City)。通过数据库中的每个字段与最初读取的值相比较,我们很容易确定是否同时有其他用户修改了某个字段。如果 Where 子句不 成立 ,就没有记录会被修改, 与此 同时还引发了一个 “ 数据库并发 ” 异常。如果数据源的某个字段 为 空值( NULL),生成的 SQL 语句同样验证最初读取的记录是否 也为 空值。 UPDATE Customers SET CustomerID = CustomerID, CompanyName = CompanyName, ContactName = ContactName, ContactTitle = ContactTitle, City = City WHERE (CustomerID = Original_CustomerID) AND (City = Original_City OR Original_City IS NULL AND City IS NULL) AND (CompanyName = Original_CompanyName) AND (ContactName = Original_ContactName OR Original_ContactName IS NULL AND ContactName IS NULL) AND (ContactTitle = Original_ContactTitle OR Original_ContactTitle IS NULL AND nts 理学院毕业论文 第 5 页 /共 20 页 ContactTitle IS NULL); SELECT CustomerID, CompanyName, ContactName, ContactTitle, City FROM Customers WHERE (CustomerID = CustomerID) 不使用开放式并 发的 Update 语句 这个例子 更改 了 “ 数据适配器 配置 向导 ” 的高级选项,没有选 中“ 使用开放式并发 ”选项 。 以下的语句 表明 :只要数据库中一条记录满足 CustomerID = Original_CustomerID ,则所有的字段都会被更新。不管这条记录 现在 是什么样的值,它都将被设置为通过 SQL语句传递到数据源的值。 在 这里没有任何关于并发的检测,也无法得知是否同时有其它用户在更改这条记录。 这种方式称为“最后的更新生效 ”方式。无论以前对这条记录进行过什么样的修改,更新操作都会执行。 UPDATE Customers SET CustomerID = CustomerID, CompanyName = CompanyName, ContactName = ContactName, ContactTitle = ContactTitle, City = City nts 理学院毕业论文 第 6 页 /共 20 页 WHERE (CustomerID = Original_CustomerID); SELECT CustomerID, CompanyName, ContactName, ContactTitle, City FROM Customers WHERE (CustomerID = CustomerID) 优化生成的 SQL 语句 Visual Studio .NET生成 “保持所有值 ”方式 的 SQL语句来 实现 开放式并发。虽然 这 可能 没有生成 最 高 效的 SQL 语句,但是它的却 生成 了 可以对数据源所有列(包括主键)进行并发检测的 SQL 语句。 使用 “保持所有值 ”方式实现开放式并发,当执行效率非常低下时,你可以手工修改生成的 SQL 语句 以 使它们不检查数据源的所有列。 最常见 的方式是使用时间戳或版本号字段。如果你的数据源包含一个 每次修改记录时都会更新的 时间戳字段,你只需要 验证 数据源中的时间戳和你程序中的时间戳二者是否匹配,就可以 知道 是否同时有其他用户修改了记录。 下面这条 SQL 语句 使用 检查时间戳模式。 注: 这个例子假设数据库已经设置了时间戳 字段 UPDATE Customers SET CustomerID = CustomerID, CompanyName = CompanyName, ContactName = ContactName, ContactTitle = ContactTitle, City = City nts 理学院毕业论文 第 7 页 /共 20 页 WHERE (CustomerID = Original_CustomerID) AND (TimeStamp = Original_TimeStamp); SELECT CustomerID, CompanyName, ContactName, ContactTitle, City, TimeStamp FROM Customers WHERE (CustomerID = CustomerID) 并发与 CommandBuilder 对象 当应用程序使用 SqlCommandBuilder 或者OleDbCommandBuilder 时,生成的 Update 和 Delete 语句的CommandText 属性被自动的 以 开放式并发方式 创建 。如果你不想用开放式并发,则可以通过修改 DataAdapter 对象的Update 和 Delete 命令的 CommandText 属性来实现。更多内容,请参见 OleDbCommand.CommandText 属性 或 SqlCommand.CommandText 属性 。 结论 当使用开放式并发的 “保存所有值 ”方法时, SQL 语句 在设计时由 Visual Studio .NET 的设计工具自动生成或在运行时由CommandBuilde 自动生成 。 它把数据库所有字段(包括主键)当前值与初始值进行比较 ,这可能不是一种最高效的方式 。如果你的数据使用版本号或者时间戳方式 控制并发 ,则可以通过修改生成的 SQL 语句来 获取更高效 的执行。 nts 理学院毕业论文 第 8 页 /共 20 页 英文原文 Visual Studio .NET Technical Articles How Visual Studio .NET Generates SQL Statements for Concurrency Control Steve Stein Visual Studio Team Microsoft Corporation February 2002 Summary: This paper examines the SQL statements Visual Studio .NET generates for different kinds of concurrency control, how to modify them for better performance, and how to generate a statement that does not use concurrency control. (5 printed pages) Contents Introduction Prerequisites Where Are the SQL Statements? nts 理学院毕业论文 第 9 页 /共 20 页 Concurrency and Data Adapters Optimizing the Generated SQL Statement Concurrency and Command-Builder Objects Conclusion Introduction Any application that might have multiple users simultaneously attempting to access and modify data needs some form of concurrency control. Otherwise, one users changes could inadvertently overwrite modifications from other users. The design tools in Visual Studio .NET can create SQL statements that use the check all values approach to optimistic concurrency or the last-in wins approach to updating data. This paper will explain: How each of these statement types are generated. How to modify the generated SQL statement for better performance. nts 理学院毕业论文 第 10 页 /共 20页 Prerequisites You should have an understanding of: Fundamental ADO.NET data concepts, including datasets and data adapters. For more information, see Introduction to Data Access with ADO.NET. Concurrency control basics and the options available in Visual Studio .NET. For more information, see Introduction to Data Concurrency in ADO.NET. Where Are the SQL Statements? SQL statements are located in the CommandText property of command objects. SQL commands are automatically generated at design time when configuring data adapters, and at run time when using command builder objects. For more information, see Concurrency and Command Builder Objects. Configuring Data Adapters Drag a data adapter from the Data tab of the Toolbox Drag a table from Server Explorer nts 理学院毕业论文 第 11 页 /共 20页 Modifying an existing adapter, by selecting a data adapter and clicking the Configure Data Adapter link at the bottom of the Properties window. Command Builder objects Command builder objects are created programmatically at run time. For more information, see (SqlCommandBuilder or OleDbCommandBuilder) Concurrency and Data Adapters When configuring data adapters with the Data Adapter Configuration Wizard, you can decide whether to use optimistic concurrency for the generated Update and Delete statements. Considerations and Caveats Your data source must have a primary key in order for the SQL statements to be generated to use optimistic concurrency. When creating data adapters by dragging tables from Server Explorer, the data adapter creates Update and Delete nts 理学院毕业论文 第 12 页 /共 20页 statements that are automatically configured for optimistic concurrency. If you do not want to use optimistic concurrency, you can reconfigure the data adapter: Right-click the adapter and select Configure Data Adapter from the shortcut menu, then clear the Use optimistic concurrency option of the Advanced SQL Generation Options Dialog Box. The wizard will recreate the statements without the additional code to check for concurrency violations. When reconfiguring an existing data adapter, note that the advanced settings all revert to their default state. For example, if you cleared the Use optimistic concurrency option when the adapter was originally configured, it will automatically be selected if you reconfigure it, even if you do not access the Advanced SQL Generation Options dialog box. If you select the Use existing stored procedures option in the Choose a Query Type section of the Data Adapter Configuration Wizard, the option to use optimistic concurrency is not available. The stored procedures will execute as is, and any desired concurrency checking must be done within the nts 理学院毕业论文 第 13 页 /共 20页 stored procedure, or programmatically built into your application. When commands are generated to use optimistic concurrency, no verification will be performed on binary columns to determine whether concurrent changes have been made. The resources to perform a bit-by-bit comparison of a large binary record would be extremely inefficient. SQL Statements Generated by the Wizard To understand how Visual Studio .NET constructs SQL statements that use optimistic concurrency, let us inspect the Update statement generated by the Data Adapter Configuration Wizard. We will look at the same statement generated both with and without the Use optimistic concurrency option selected in the Advanced SQL Generation Options dialog box of the wizard. You will notice the differences between statements that either use optimistic concurrency or not are located in the Where clause. nts 理学院毕业论文 第 14 页 /共 20页 Note The following examples use the Update command that is generated by running the Data Adapter Configuration Wizard, and selecting several columns from the Customers table in the Northwind sample database. Update Statement Using Optimistic Concurrency This example uses the default settings of the Data Adapter Configuration Wizard, which has the Use optimistic concurrency option selected. Note When using optimistic concurrency, the commands are generated with a second set of parameters. This second set of parameters (the ones with the Original_ prefix) store the values that are initially read from the data source. Examining the Where clause in the following statement reveals that all fields are inspected to make sure the current value for each field in the database is equal to the value that was originally read into the dataset (for example, WHERE City = Original_City). By comparing each field in the nts 理学院毕业论文 第 15 页 /共 20页 database with the original value, it is easy to determine if a concurrent user has modified a field. If the Where clause is not satisfied, no records are updated and a DBConcurrencyException is raised. If a field in the data source contains a null value, the statement also verifies the original record contained a null value. UPDATE Customers SET CustomerID = CustomerID, CompanyName = CompanyName, ContactName = ContactName, ContactTitle = ContactTitle, City = City WHERE (CustomerID = Original_CustomerID) AND (City = Original_City OR Original_City IS NULL AND City IS NULL) AND (CompanyName = Original_CompanyName) AND (ContactName = Original_ContactName OR Original_ContactName IS NULL AND ContactName IS NULL) AND (ContactTitle = nts 理学院毕业论文 第 16 页 /共 20页 Original_ContactTitle OR Original_ContactTitle IS NULL AND ContactTitle IS NULL); SELECT CustomerID, CompanyName, ContactName, ContactTitle, City FROM Customers WHERE (CustomerID = CustomerID) Update Statement Without Optimistic Concurrency This example modifies the advanced settings of the Data Adapter Configuration Wizard and clears the Use optimistic concurrency option. Examining the following statement reveals that all fields will be updated as long as a record exists in the database where CustomerID = Original_CustomerID. No matter what values exist in this record, they will all be set to the values passed through this statement. There is no verification to check if a concurrent user has modified the record. This is called the last-in wins approach, because nts 理学院毕业论文 第 17 页 /共 20页 no matter what modifications have been performed on the record, the update will still be performed. UPDATE Customers SET CustomerID = CustomerID, CompanyName = CompanyName, ContactName = ContactName, ContactTitle = ContactTitle, City = City WHERE (CustomerID = Original_CustomerID); SELECT CustomerID, CompanyName, ContactName, ContactTitle, City FROM Customers WHERE (CustomerID = CustomerID) Optimizing the Generated SQL Statement Visual Studio .NET generates SQL statements that use the check all values approach to optimistic concurrency. Although this may not generate the most efficient statement, it does create a statement that can check for concurrency violations on any data source containing a primary key. If the check all values approach to optimistic concurrency proves inefficient, you can modify the generated command nts 理学院毕业论文 第 18 页 /共 20页 text so it does not have to check every original value against the values in the data source. The most common way to accomplish this is with a timestamp or version field. If your data contains a timestamp field that is updated every time the data changes, you need only check the timestamp in your applications record against the timestamp in the data source to determine if a concurrent user has changed the record. The following SQL statement has been modified
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
提示  人人文库网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:机械毕业设计英文外文翻译24Visual Studio .NET如何为并发控制生成SQL语句
链接地址:https://www.renrendoc.com/p-553276.html

官方联系方式

2:不支持迅雷下载,请使用浏览器下载   
3:不支持QQ浏览器下载,请用其他浏览器   
4:下载后的文档和图纸-无水印   
5:文档经过压缩,下载后原文更清晰   
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

网站客服QQ:2881952447     

copyright@ 2020-2025  renrendoc.com 人人文库版权所有   联系电话:400-852-1180

备案号:蜀ICP备2022000484号-2       经营许可证: 川B2-20220663       公网安备川公网安备: 51019002004831号

本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知人人文库网,我们立即给予删除!