locked
Query SqlConnection for enlistment RRS feed

  • Question

  • Is it possible to find out whether specified SqlConnection is enlited in a transaction?
    Friday, February 10, 2012 10:33 PM

Answers

All replies

  • AFIK, There is no direct way of checking enlishment.Long gape i was refering below code block to check.

            public static bool CheckEnlisted(SqlConnection con)
            {
                object myObject = typeof(SqlConnection).GetField("_innerConnection", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(con);
                myObject = myObject.GetType().GetField("_enlistedTransaction", BindingFlags.Instance | BindingFlags.NonPublic);
                return myObject != null;
            }
    Hope this would help you.

    Lingaraj Mishra

    • Proposed as answer by Allen_MSDN Wednesday, February 15, 2012 3:32 AM
    • Marked as answer by Allen_MSDN Monday, February 20, 2012 1:56 AM
    • Unmarked as answer by Alex V. Ivanoff Monday, February 20, 2012 1:58 AM
    Sunday, February 12, 2012 12:33 PM
  • So, there is no reliable way.
    Tuesday, February 14, 2012 6:28 PM