Schultz9999
Schultz9999

Reputation: 8936

stored procedure doesn't return control to C# code

I am experiencing very strange issue: the stored procedure doesn't return even though the data is properly and timely inserted. The most staggering thing about this is that the record time stamp field is always populated within milliseconds so the data seems getting into the tables very fast. But return never happens.

Important part of all this is that it only happens under the load -- individual requests are just fine. Only when DB is stressed enough, this thing starts happening.

Any ideas are welcome because I have very little understanding what can be wrong.

Here is simplified C# part of it:

try 
{
    using (var conn = new SqlConnection(connString))
    {
        conn.Open();

        using (var cmd = new SqlCommand(conn, ....)
        {
            cmd.CommandType = StoredProcedure;

            cmd.ExecuteNonQuery();

            // THIS NEVER EXECUTES:
            ReportSuccess();
        }
    }
}
catch (TimeoutException)
{
    // EXCEPTION HERE
}

And the stored procedure:

CREATE PROCEDURE dbo.Blah
BEGIN
    INSERT dbo.MyTable VALUES (...)

    INSERT dbo.MyTable2...

    -- Here is where everything stops.

END

UPDATE: we did out best to correlate timeouts and SQL server activity and it appears non-app user activity was causing locks. The process is designed to allow very quick inserts and very quick reads. However some individuals would execute quite expensive queries without actually using DIRTY READ policy, which was tipping over the fragile hardware load balance. Thanks for all your tips though.

Upvotes: 2

Views: 266

Answers (1)

humblelistener
humblelistener

Reputation: 1456

Based on the information provided, my best guess is that there is a contingency problem in your stored procedure.

Try using transaction in your stored procedure. If my theory is correct, no record will be inserted.

Check if there are any locks being acquired on MyTable2. If you doing a big select on that table elsewhere, ensure you are using nolock.

Upvotes: 1

Related Questions