Setting the database connection when using a TransactionScope
        Posted  
        
            by eych
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by eych
        
        
        
        Published on 2010-04-26T21:05:17Z
        Indexed on 
            2010/04/30
            13:17 UTC
        
        
        Read the original article
        Hit count: 572
        
transactionscope
|database-connection
Does the database connection have to be set inside a TransactionScope?
Or can I set it in the ctor and then have instance methods create up a TransactionScope?  
EDIT: e.g.
Public Sub New()
   Dim conn = new SqlConnection(...connection string)
Public Sub SomeClassMethod()
   using ts as new TransactionScope
      //conn has already been initialized
      //so, here you can set commands, ExecuteDataSet, etc.
vs
Public Sub New()
   //nothing here
Public Sub SomeClassMethod()    
   using ts as new TransactionScope
      conn = new SqlConnection(...connection string)
      set commands, ExecuteDataSet, etc.
the question is do you need to create the connection to the database after you've created a TransactionScope or can it be done before?
© Stack Overflow or respective owner