title: CLR trigger executing incorrectly the first time
body: <p>I have a CLR trigger, and the first thing it does is get the table name associated with the trigger, as follows:</p>
  
  <pre><code>public static void MyTrigger()
  {
      using (SqlConnection conn = new SqlConnection(@"context connection=true"))
      {
          conn.Open();
  
          command.CommandText = @"SELECT object_name(resource_associated_entity_id) FROM sys.dm_tran_locks WHERE request_session_id = @@spid and resource_type = 'OBJECT'";
          string tableName = command.ExecuteScalar().ToString();
  
          //etc...
      }
  }
  </code></pre>
  
  <p>The first time the trigger is executed, the table name returned by the above command is always <code>syscolpars</code>. If the trigger is executed again, the table name is returned correctly.</p>
  
  <p>The database engine is SQL Server 2014 Express.</p>
  
  <p>Why is this happening?</p>