休眠等待命令会阻止其他事务

发布于 2024-10-06 09:49:22 字数 1065 浏览 0 评论 0原文

我在 ASP.NET 2.0 上有一个大型 Web 应用程序。 用户可以在那里打开对象编辑器并进行一些更改。他们不能同时打开同一个对象。

在他们按下“保存”按钮后,所有更改过程都会通过回发保存在服务器上。

我正在使用事务来保存。在保存操作确定之前,需要完成很多程序、检查和其他操作。

using (SqlConnection con = .........)
        {
            SqlTransaction trans = null;
            try
            {
                con.Open();
                trans=con.BeginTransaction(IsolationLevel.ReadUncommitted);
                ........operations.........
                trans.Commit();
            }
            catch (Exception e)
            {
                try { if (trans != null) trans.Rollback(); }
                catch { }
                throw new MyException("SQL Exception: " + e.Message, e);
            }
            finally
            {
                if (con != null && con.State == ConnectionState.Open) con.Close();
            }
        }

对我来说这段代码非常安全。

但周期性地发生: 此 Web 应用程序中在 mssql 上保存操作的一个进程变为“睡眠/等待”。 其他用户调用的其他进程被该进程锁定并组织队列。

其中一个抛出了超时异常......但其他人正在等待。

所以,我的问题是:我的代码是否有一些错误的操作导致命令进入睡眠/等待状态? 也许有一些技巧?

I have a big web application on asp.net 2.0.
Usere open object editor there and makes some changes. They can not open the same object at one time.

After they press "save" btn all changes process to save on server via postback.

I am using transaction for save. There are a lot of procedures, checks and others to be done before saving operation is OK.

using (SqlConnection con = .........)
        {
            SqlTransaction trans = null;
            try
            {
                con.Open();
                trans=con.BeginTransaction(IsolationLevel.ReadUncommitted);
                ........operations.........
                trans.Commit();
            }
            catch (Exception e)
            {
                try { if (trans != null) trans.Rollback(); }
                catch { }
                throw new MyException("SQL Exception: " + e.Message, e);
            }
            finally
            {
                if (con != null && con.State == ConnectionState.Open) con.Close();
            }
        }

For me this code is quite safe.

But periodicaly happens:
one process from this web application on saving operation on mssql became "sleeping/awaiting".
and others processes called by other users became locked by this process and organiza a queue.

One of them threw timeout excetion.....but others are waiting.

So, my question is: does my code have some bad operation that allows command to became sleeping/awaiting?
May be there are some tricks?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如此安好 2024-10-13 09:49:22

由于您在事务内执行大量数据库操作,因此数据库锁可能会阻塞您的应用程序。

您可以使用 sp_who2 存储过程(此处有更多详细信息)来查看是否有通过检查结果的 BlkBy 列来查看服务器上的任何块。

您可能还想检查 Sql Server 锁僵局

Since you are doing a lot DB of operations inside a transaction there is a chance that a database lock is blocking your application.

You can use the sp_who2 stored procedure (there are more details on it here) to see if there any blocks on your server, by checking the BlkBy column of the result.

You might also want to check the following links on Sql Server locks and deadlocking

我的黑色迷你裙 2024-10-13 09:49:22

Может ли это быть связано с репликацией。 В момент когда наблюдаются описанные выше тормоза репликация начинает сильно тормозить。 И пишет:
该进程无法连接到发布者“эта бд”。 (来源:MSSQL_REPL,错误号:MSSQL_REPL20084)
获取帮助:http://help/MSSQL_REPL20084

· TCP 提供程序:连接尝试失败,因为连接方在之后没有正确响应一段时间后,或由于连接的主机未能响应而建立的连接失败。 (来源:MSSQLServer,错误号:10060)
获得帮助:
· 与服务器建立连接时发生错误。当连接到SQL Server 2005时,出现此故障的原因可能是SQL Server在默认设置下不允许远程连接。 (来源:MSSQLServer,错误号:10060)
获得帮助:
· 登录超时已过期(来源:MSSQLServer,错误号:0)
获得帮助:
· 由于查询超时,合并进程无法执行查询。如果此故障仍然存在,请增加该进程的查询超时。排除故障时,请使用详细历史记录重新启动同步,并指定要写入的输出文件。 (来源:MSSQLServer,错误号:0)
获得帮助:
Эта БД является источником репликации。

Может ли это быть связано с репликацией. В момент когда наблюдаются описанные выше тормоза репликация начинает сильно тормозить. И пишет:
The process could not connect to Publisher 'эта бд'. (Source: MSSQL_REPL, Error number: MSSQL_REPL20084)
Get help: http://help/MSSQL_REPL20084

· TCP Provider: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (Source: MSSQLServer, Error number: 10060)
Get help:
· An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (Source: MSSQLServer, Error number: 10060)
Get help:
· Login timeout expired (Source: MSSQLServer, Error number: 0)
Get help:
· The merge process failed to execute a query because the query timed out. If this failure continues, increase the query timeout for the process. When troubleshooting, restart the synchronization with verbose history logging and specify an output file to which to write. (Source: MSSQLServer, Error number: 0)
Get help:
Эта БД является источником репликации.

记忆之渊 2024-10-13 09:49:22

但主要问题是第一个进程没有抛出超时异常。它睡得很沉,因为我们不杀他。这是主要问题。

But the main problem is that the first process does not threw timeout exception. It is sleeping as log as we do not kill him. That is the main problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文