title: C# with SQL Server Application Roles: Cannot continue the execution because the session is in the kill state
body: <p>I'm attempting to implement an Application Role with my connections in a C# Winforms Desktop application.  Everything works fine with the first connection, and I am closing it properly with a using{} construct.  However, when I create a second connection, I get the "Cannot continue the execution because the session is in the kill state" error.  Any idea as to why I'm getting this error and how to troubleshoot?  Here is my code where I get the error along with my method to set the application role:  </p>
  
  <pre><code>try
  {
      using (SqlConnection connection = new SqlConnection(connectionString))
      {
          connection.Open();
          oAppRole.setApplicationRole(connection);
  
          string query = "&lt;sql statement here&gt;";
  
          using (var cmd = new SqlCommand(query, connection))
          {
              cmd.Parameters.AddWithValue("@EmpID", empID);
              cmd.Parameters.AddWithValue("@ExpDate", priorExpDate);
  
              SqlDataAdapter da = new SqlDataAdapter(cmd);
              da.Fill(dtReturnTable);
          }
      }
  }
  catch (Exception ex)
  {
      throw ex;
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public bool setApplicationRole(SqlConnection connection)
  {
      bool retVal = true;
      string procName = "sys.sp_setapprole";
  
      SqlCommand cmd = new SqlCommand(procName);
      cmd.CommandType = System.Data.CommandType.StoredProcedure;
      cmd.Connection = connection;
  
      // Parameter for Application Role Name
      SqlParameter parmAppRoleName = new SqlParameter();
      parmAppRoleName.ParameterName = "@rolename";
      parmAppRoleName.Value = "myAppRole";
      cmd.Parameters.Add(parmAppRoleName);
  
      // Parameter for Application Role Password
      SqlParameter parmAppRolePwd = new SqlParameter();
      parmAppRolePwd.ParameterName = "@password";
      parmAppRolePwd.Value = "myPassword";
      cmd.Parameters.Add(parmAppRolePwd);
  
      try
      {
          cmd.ExecuteNonQuery();
      }
      catch (Exception ex)
      {
          retVal = false;
          throw(ex);
      }
  
      return retVal;
  }
  </code></pre>