简体   繁体   English

使用 MS Access 更新 SQL Server 视图上的查询超时

[英]Update Query Timeout on SQL Server View with MS Access

I am having some trouble with updates to an SQL Server View through MS Access.我在通过 MS Access 更新 SQL Server 视图时遇到了一些问题。 The set of tables used for this is built off of a base table.用于此的一组表是基于基表构建的。 This base table is of this format.这个基表就是这种格式。

Id    int (not-nullable; auto-assigned)
A1    varchar(50) (nullable)
A2    varchar(50) (nullable)
B1    varchar(50) (nullable)
B2    varchar(50) (nullable)
C1    varchar(50) (nullable)
C2    varchar(50) (nullable)

One row on this table is updated by multiple groups of users in our company.该表中的一行由我们公司的多组用户更新。 For instance, user group "A" updates columns "A1" and "A2", user group "B" updates columns "B1" and "B2", and so forth.例如,用户组“A”更新列“A1”和“A2”,用户组“B”更新列“B1”和“B2”,依此类推。 However, we also want to prevent user group "A" from updating the columns of user group "B".但是,我们还希望阻止用户组“A”更新用户组“B”的列。 To accomplish this, I set up a view containing the columns appropriate for each user group.为此,我设置了一个视图,其中包含适合每个用户组的列。 For instance, the view for user group "A" would only contain the columns "Id", "A1", and "A2".例如,用户组“A”的视图将只包含“Id”、“A1”和“A2”列。 Then I set the "Bind To Schema" option on the views in SSMS to "Yes", and I set up a unique, clustered index on the "Id" column on each of the views.然后我将 SSMS 中视图的“绑定到架构”选项设置为“是”,并在每个视图的“Id”列上设置一个唯一的聚集索引。 In MS Access, I connect to these views as linked tables using an ODBC connection.在 MS Access 中,我使用 ODBC 连接将这些视图作为链接表连接。 When I open the tables in MS Access in design view and check the indexes, it does properly identify the "Id" column as the primary key.当我在设计视图中打开 MS Access 中的表并检查索引时,它确实将“Id”列正确标识为主键。

Here is where the trouble comes in: When I try to update a record through MS Access in one of the views, sometimes the update runs instantly, but sometimes the update times out.这就是问题所在:当我尝试通过 MS Access 在其中一个视图中更新记录时,有时更新会立即运行,但有时更新会超时。 Here is the error that I get.这是我得到的错误。

超时错误消息

"SM_Notes_Bridge" is the actual name of one of my views. “SM_Notes_Bridge”是我的一个视图的实际名称。 Almost all previous answers that I can find online say to increase the amount of time before the update times out in MS Access, which seems like it is not a solution for my problem as the update either runs instantly or times out.我可以在网上找到的几乎所有以前的答案都说要增加 MS Access 中更新超时之前的时间量,这似乎不是我的问题的解决方案,因为更新要么立即运行,要么超时。 There is no middle ground.没有回旋的余地。

Another note is that I am currently the only one using this base table and these views.另一个注意事项是,我目前是唯一一个使用此基表和这些视图的人。 Also, important systems are developed around that base table structure, so changing its structure will take a lot of convincing.此外,重要的系统是围绕该基表结构开发的,因此更改其结构需要很多说服力。

By creating an unique index on a schema bound view, you're creating an indexed view, also called a materialized view .通过在模式绑定视图上创建唯一索引,您正在创建索引视图,也称为物化视图

A relevant property of indexed views:索引视图的相关属性:

When executing DML on a table referenced by a large number of indexed views, or fewer but very complex indexed views, those referenced indexed views will have to be updated as well.当对由大量索引视图或较少但非常复杂的索引视图引用的表执行 DML 时,这些引用的索引视图也必须更新。 As a result, DML query performance can degrade significantly, or in some cases, a query plan cannot even be produced ( MSDN ).因此,DML 查询性能会显着降低,或者在某些情况下,甚至无法生成查询计划 ( MSDN )。

Thus, creating multiple indexed views on a table that is updated often is a big no-no!因此,在经常更新的表上创建多个索引视图是一个很大的禁忌! Review this MSDN page for further explanation when and when not to use an indexed view.查看此 MSDN 页面以进一步说明何时以及何时不使用索引视图。 Every insert and update will have to propagate to all the indexed views, and will cause locks on those views as well.每个插入和更新都必须传播到所有索引视图,并且也会导致对这些视图的锁定。

Drop the indexes on ALL views on that table.删除该表上所有视图的索引。 As far as you've told me, there's no reason at all to use indexed views and they will hurt performance in a major way when executing updates.就您告诉我的而言,完全没有理由使用索引视图,并且它们会在执行更新时以主要方式损害性能。 Even if that didn't fix this issue, it will improve performance.即使这没有解决这个问题,它也会提高性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM