C # cmd.ExecuteScalar (): "Unable to continue execution because the session is in kill state."

Getting a strange exception from ExecuteScalar()that I cannot find on the Internet:

Unable to continue execution because the session is in a kill state.

I am using SqlConnection / SqlCommand

The command is a basic INSERT INTO ... with 105 columns (and 105 parameters for setting the column data) followed by SELECT SCOPE_IDENTITY ();

I checked the connection string - this is correct and the connection is open.

I'm not even sure that this error tells me to know where to start looking at it.

So what does this error mean? How does a session in kill state begin?

The code is pretty straight forward:

using (SqlConnection conn = new SqlConnection(connString))
{
    conn.Open();
    using (SqlCommand cmd = new SqlCommand(@"INSERT INTO VendorNote (VendorId, AdminComment...) VALUES (@VendorId, @AdminComment, ...); SELECT SCOPE_IDENTITY(); ", conn))
    {
        cmd.Parameters.AddWithValue("@VendorId", VendorId);
        cmd.Parameters.AddWithValue("@AdminComment", AdminComment);
        Id = (int) cmd.ExecuteScalar();
    }
}
+4
2

!

, . , - , "" ( ), .

- , , - .

, - - , , .

+6

:

const string sqlString = "INSERT INTO dbo.Table ( ....) " +
                         "               VALUES ( .... );" +
                         "SELECT SCOPE_IDENTITY();";
using (conn)
{
    using (var cmd = new SqlCommand(sqlString, conn))
    {
        cmd.Parameters.AddWithValue("@param", param);

        cmd.CommandType = CommandType.Text;
        conn.Open();
        return (int) (decimal) cmd.ExecuteScalar();

    }
}

,

+1

Source: https://habr.com/ru/post/1622131/


All Articles