Subject [firebird-support] Firebird .Net Provider - Static Connection and transactions C#
Author Martin Dew
Hi,



I have a static FBConnection Class in c#



public class OwlFBConnection {

static private FbConnection db_connect = null;



/// <summary>

/// The static instance of the database connection

/// </summary>

static public FbConnection Connection {

get {

lock(typeof(OwlFBConnection)) {

if (db_connect == null) {

string connectionString =
string.Empty;

FbConnectionStringBuilder cs =
new FbConnectionStringBuilder();

cs.DataSource =
Configuration.Current.Get("OWLV3INTERFACE","DBDataSource");

cs.Database =
Configuration.Current.Get("OWLV3INTERFACE","DBDatabase");

cs.UserID =
Configuration.Current.Get("OWLV3INTERFACE","DBUserID");

cs.Password =
Configuration.Current.Get("OWLV3INTERFACE","DBPassword");

cs.Dialect =
Convert.ToByte(Configuration.Current.Get("OWLV3INTERFACE","DBDialect"));


connectionString =
cs.ToString();

Debug.WriteLine("Creating
FB.Net Connection");

db_connect = new
FbConnection(connectionString);


Debug.WriteLine("Created
FB.Net Connection");

db_connect.Open();

Debug.WriteLine("Called Open
on Static FB.Net Connection");

}

}

return db_connect;

}



set {

if (db_connect != null) {

db_connect.Close();

}

db_connect = value;

}

}

}



I then have a method in another class;



public DataSet RunSQL(string selectStatement) {

Debug.WriteLine(selectStatement);

FbConnection db_connect = OwlFBConnection.Connection;






DataSet ds = new DataSet();

Debug.WriteLine("Start a Transaction");

FbTransaction transaction =
db_connect.BeginTransaction();

try {

Debug.WriteLine("Setup and Fill the Adapter with
data");

FbCommand dbCommand = new
FbCommand(selectStatement,db_connect, transaction);


FbDataAdapter dbDataAdapter = new
FbDataAdapter(dbCommand);

dbDataAdapter.Fill(ds);

Debug.WriteLine("Completed dbDataAdapter.Fill");

return ds;

} finally {

transaction.Commit();

ds.Dispose();


}

}



When 2 different threads call RunSQL I get an error raised;



"A transaction is currently active. Parallel transactions are not
supported."



My question is, how can I use this in a threaded environment to run
multiple queries against one Connection at the same time ?



Or how can I achieve the same thing in a different manner.



Thanks for anything help you can offer.



Regards



Martin



[Non-text portions of this message have been removed]