什么原因导致“非阻塞套接字上的操作会阻塞"错误?在 MSSQL 中? [英] What causes the error "Operation on non-blocking socket would block" in MSSQL?

查看:47
本文介绍了什么原因导致“非阻塞套接字上的操作会阻塞"错误?在 MSSQL 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:异常查询是 'CREATE NONCLUSTERED INDEX[I1] ON AllAccounts_BAK([Master_received_Day] ASC)' 出现一个或多个错误.错误:异常内部异常无法从传输连接读取数据:对非阻塞套接字的操作将阻塞.

ERROR: Exception query was 'CREATE NONCLUSTERED INDEX[I1] ON AllAccounts_BAK ( [Master_received_Day] ASC )' with exception One or more errors occurred. ERROR: Exception Inner Exception Unable to read data from the transport connection: Operation on non-blocking socket would block.

这是执行此查询的 C# 代码:

Here is the Code in C# that executes this query:

private void ExecuteQuery(string qStr)
{
    using (SqlConnection cnx = new SqlConnection(_ConnectionString))
    {
        using (SqlCommand cmd = new SqlCommand(qStr, cnx))
        {
            cmd.Connection.Open();
            cmd.ExecuteNonQuery();
        }
    }
}

在查询之前测试连接字符串,以确保它会通过检索两行数据进行连接.没有其他人使用该数据库.该查询已在 SQL 操作控制台中进行了测试,并且可以正常工作.它是到 Azure 数据库的 tcp 连接.我已经使用这种代码加载了数据并完成了查询.是什么导致这种错误?

The connection string is tested just before the query to be sure that it will do a connection by retrieving two rows of data. No-one else uses the database. The query has been tested in the SQL Operation Console and it works. It is a tcp connection to an Azure database. I have loaded data and done queries using this kind of code. What causes this kind of error?

推荐答案

嗯,除了连接超时和远程连接超时之外,我发现还有另一个隐藏在 MS 文档中的问题.如果在我的示例中,将打开和执行的两行替换为:

Well, In addition to connection timeouts, and remote connection timeouts, there is another that I found buried in the bowels of MS documentation. If in my example, one replaces the two lines doing the open and execution with:

  cmd.Connection.Open();
  cmd.CommandTimeout = 0; // 0 sets it so the "command" doesn't time out!
  cmd.ExecuteNonQuery();

添加该行后,它工作正常!我很惊讶这没有更明显地说明.如果有人能解释一下,那就太好了!

After adding that line, it works fine! I'm surprised that this isn't stated more obviously. If someone could explain this, it would be great!

这篇关于什么原因导致“非阻塞套接字上的操作会阻塞"错误?在 MSSQL 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆