B
bz
Hi,
I have two typed datasets I use on the same form. Each contains some
TableAdapters and corresponding data tables. The TableAdapters
contains, beside default Fill methods (to populate the DataTable) some
queries which returns scalar or some action queries (insert / delete)
which return nothing, just work on database
What I need is to perform some actions as above (various processing on
both datasets) but under the same transaction.
Typed dataset does not expose the Connection or Transaction property,
but I enhanced the Table Adapter classes for the tableadapters I want
to work with under same transaction as below, to assign a Connection:
namespace AssurantieService.BL.DataSets.AppSecurityDSTableAdapters
{
public partial class as_ExtAppSecurityTA :
System.ComponentModel.Component
{
/// <summary>
/// Set the connection to be able to work with transactions
/// </summary>
public void SetConnection(IDbConnection parConn)
{
foreach (SqlCommand cmd in _commandCollection)
cmd.Connection = (SqlConnection)parConn;
}
}
}
And I created a SessionManager class which basically creates a
connection, start transaction, I want to use the connection from this
class to assign to TA's Connection prop, and process all inside a
using statement
The SessionManager basically looks as below
public SessionManager(string connectionString)
{
try
{
prvDataConnection = new
SqlConnection(connectionString);
if (prvDataConnection.State != ConnectionState.Open)
prvDataConnection.Open();
}
catch (Exception ex)
{
ClearSession();
ErrorHandler.LogError(ex);
throw new SessionManagerException("ConnError"), ex);
}
}
public SessionManager(string connectionString, bool
useTransaction)
: this(connectionString)
{
if (useTransaction)
try
{
if (prvTransaction == null)
{
prvTransaction =
prvDataConnection.BeginTransaction();
prvInTransaction = true;
prvUseTransaction = true;
}
}
catch (Exception ex)
{
ClearSession();
ErrorHandler.LogError(ex);
throw new SessionManagerException("TranError"),
ex);
}
}
However, this is not working. When I execute some action queries or
scalar from tableadapters I get various error messages - Connection
for Command object is not set, etc
Can anyone help me? Or is there any other way to create a transaction
across different connections?
Thanks you
I have two typed datasets I use on the same form. Each contains some
TableAdapters and corresponding data tables. The TableAdapters
contains, beside default Fill methods (to populate the DataTable) some
queries which returns scalar or some action queries (insert / delete)
which return nothing, just work on database
What I need is to perform some actions as above (various processing on
both datasets) but under the same transaction.
Typed dataset does not expose the Connection or Transaction property,
but I enhanced the Table Adapter classes for the tableadapters I want
to work with under same transaction as below, to assign a Connection:
namespace AssurantieService.BL.DataSets.AppSecurityDSTableAdapters
{
public partial class as_ExtAppSecurityTA :
System.ComponentModel.Component
{
/// <summary>
/// Set the connection to be able to work with transactions
/// </summary>
public void SetConnection(IDbConnection parConn)
{
foreach (SqlCommand cmd in _commandCollection)
cmd.Connection = (SqlConnection)parConn;
}
}
}
And I created a SessionManager class which basically creates a
connection, start transaction, I want to use the connection from this
class to assign to TA's Connection prop, and process all inside a
using statement
The SessionManager basically looks as below
public SessionManager(string connectionString)
{
try
{
prvDataConnection = new
SqlConnection(connectionString);
if (prvDataConnection.State != ConnectionState.Open)
prvDataConnection.Open();
}
catch (Exception ex)
{
ClearSession();
ErrorHandler.LogError(ex);
throw new SessionManagerException("ConnError"), ex);
}
}
public SessionManager(string connectionString, bool
useTransaction)
: this(connectionString)
{
if (useTransaction)
try
{
if (prvTransaction == null)
{
prvTransaction =
prvDataConnection.BeginTransaction();
prvInTransaction = true;
prvUseTransaction = true;
}
}
catch (Exception ex)
{
ClearSession();
ErrorHandler.LogError(ex);
throw new SessionManagerException("TranError"),
ex);
}
}
However, this is not working. When I execute some action queries or
scalar from tableadapters I get various error messages - Connection
for Command object is not set, etc
Can anyone help me? Or is there any other way to create a transaction
across different connections?
Thanks you