What causes the error "Operation on non-blocking socket would block" in MSSQL?

Viewed 4263

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.

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();
        }
    }
}

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?

1 Answers

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!

Related