public void BeginTrasactionTest() { string connectionString = this.BuildConnectionString(); FbConnection conn01 = new FbConnection(connectionString); conn01.Open(); FbTransaction txn01 = conn01.BeginTransaction(IsolationLevel.Unspecified); txn01.Rollback(); conn01.Close(); FbConnection conn02 = new FbConnection(connectionString); conn02.Open(); FbTransaction txn02 = conn02.BeginTransaction(IsolationLevel.ReadCommitted); txn02.Rollback(); conn02.Close(); FbConnection conn03 = new FbConnection(connectionString); conn03.Open(); FbTransaction txn03 = conn03.BeginTransaction(IsolationLevel.ReadUncommitted); txn03.Rollback(); conn03.Close(); FbConnection conn04 = new FbConnection(connectionString); conn04.Open(); FbTransaction txn04 = conn04.BeginTransaction(IsolationLevel.RepeatableRead); txn04.Rollback(); conn04.Close(); FbConnection conn05 = new FbConnection(connectionString); conn05.Open(); FbTransaction txn05 = conn05.BeginTransaction(IsolationLevel.Serializable); txn05.Rollback(); conn05.Close(); }
/// <include file='Doc/en_EN/FbRemoteEvent.xml' path='doc/class[@name="FbRemoteEvent"]/constructor[@name="ctor(FbConnection, System.Array)"]/*'/> public FbRemoteEvent(FbConnection connection, string[] events) { if (connection == null || connection.State != System.Data.ConnectionState.Open) { throw new InvalidOperationException("Connection must valid and open"); } this.connection = connection; this.revent = connection.InnerConnection.Database.CreateEvent(); this.revent.EventCountsCallback = new EventCountsCallback(this.OnRemoteEventCounts); if (events != null) { this.AddEvents(events); } }
public void ConnectionPoolingTest() { string cs = this.BuildConnectionString(true); FbConnection myConnection1 = new FbConnection(cs); FbConnection myConnection2 = new FbConnection(cs); FbConnection myConnection3 = new FbConnection(cs); // Open two connections. Console.WriteLine ("Open two connections."); myConnection1.Open(); myConnection2.Open(); // Now there are two connections in the pool that matches the connection string. // Return the both connections to the pool. Console.WriteLine ("Return both of the connections to the pool."); myConnection1.Close(); myConnection2.Close(); // Get a connection out of the pool. Console.WriteLine ("Open a connection from the pool."); myConnection1.Open(); // Get a second connection out of the pool. Console.WriteLine ("Open a second connection from the pool."); myConnection2.Open(); // Open a third connection. Console.WriteLine ("Open a third connection."); myConnection3.Open(); // Return the all connections to the pool. Console.WriteLine ("Return all three connections to the pool."); myConnection1.Close(); myConnection2.Close(); myConnection3.Close(); // Clear pools FbConnection.ClearAllPools(); }
/// <summary> /// Gets a <see cref="FbConnection"/> instance. /// </summary> /// <returns>An instance of the <see cref="FbConnection"/> class.</returns> protected internal FbConnection ProvideConnection() { if (requiresNewConnection) { if ((this.sqlConnection != null) || (this.sqlConnection.State != ConnectionState.Closed) || (this.sqlConnection.State != ConnectionState.Broken)) { this.sqlConnection.Close(); } this.sqlConnection = new FbConnection(this.connectionString.ToString()); } if (this.sqlConnection.State == ConnectionState.Closed) { this.sqlConnection.Open(); } return this.sqlConnection; }
/// <include file='Doc/en_EN/FbDataReader.xml' path='doc/class[@name="FbDataReader"]/method[@name="Close"]/*'/> public void Close() { bool closeConnection = false; if (this.IsClosed) { return; } this.isClosed = true; this.position = STARTPOS; if (this.connection != null) { if ((this.behavior & CommandBehavior.CloseConnection) == CommandBehavior.CloseConnection) { closeConnection = true; } } if (this.command != null && !this.command.IsDisposed) { if (this.command.CommandType == CommandType.StoredProcedure) { // Set values of output parameters this.command.SetOutputParameters(); } if (this.command.HasImplicitTransaction) { // Commit implicit transaction if needed this.command.CommitImplicitTransaction(); } // Set null the active reader of the command this.command.ActiveReader = null; } if (closeConnection) { this.connection.Close(); } this.command = null; this.connection = null; this.row = null; this.schemaTable = null; this.fields = null; }
public FbConnectionInternal(FbConnectionString options, FbConnection owningConnection) { this.options = options; this.owningConnection = owningConnection; }
/// <include file='Doc/en_EN/FbDataAdapter.xml' path='doc/class[@name="FbDataAdapter"]/constructor[@name="ctor(System.String,System.String)"]/*'/> public FbDataAdapter(string selectCommandText, string selectConnectionString) : base() { FbConnection connection = new FbConnection(selectConnectionString); this.SelectCommand = new FbCommand(selectCommandText, connection); }
/// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/method[@name="ClearPool(FbConnection)"]/*'/> public static void ClearPool(FbConnection connection) { FbPoolManager manager = FbPoolManager.Instance; manager.ClearPool(connection.ConnectionString); }
private void OpenDbConnection(string db, string uid, string pwd) { try { FbConnectionStringBuilder cs = new FbConnectionStringBuilder(); cs.DataSource = "localhost"; cs.Database = database; cs.UserID = userID; cs.Password = password; cs.Dialect = 3; dbSource = cs.ToString(); dbConnection = new FbConnection (dbSource); dbConnection.Open (); dbCommand = new FbCommand (null, dbConnection); dbDataAdapter = new FbDataAdapter (dbCommand); } catch { dbConnection = null; IO.Error ("Unable to open database connection:\n{0}", dbSource); } }
/// <summary> /// Constructor with ADO.NET Npgsql connection. /// </summary> public FirebirdDbProvider(FbConnection conn) { connection = conn; }
public void FbConnectionStringBuilderTest() { FbConnectionStringBuilder cs = new FbConnectionStringBuilder(); cs.DataSource = ConfigurationSettings.AppSettings["DataSource"]; cs.Database = ConfigurationSettings.AppSettings["Database"]; cs.Port = Convert.ToInt32(ConfigurationSettings.AppSettings["Port"]); cs.UserID = ConfigurationSettings.AppSettings["User"]; cs.Password = ConfigurationSettings.AppSettings["Password"]; cs.ServerType = Convert.ToInt32(ConfigurationSettings.AppSettings["ServerType"]); cs.Charset = ConfigurationSettings.AppSettings["Charset"]; cs.Pooling = Convert.ToBoolean(ConfigurationSettings.AppSettings["Pooling"]); using (FbConnection c = new FbConnection(cs.ToString())) { c.Open(); } }
private FbConnection GetConnection() { string connectionString = "User=SYSDBA;" + "Password=masterkey;" + @"Database=mercury.fdb;" + //"DataSource=localhost;" + "Charset=UNICODE_FSS;" + "Pooling=true;" + "ServerType=1;"; FbConnection conn = new FbConnection(connectionString.ToString()); conn.Open(); return conn; }
/// <summary> /// Creates an instance of FbBatchExecution engine with the given /// connection. /// </summary> /// <param name="sqlConnection">A <see cref="FbConnection"/> object.</param> public FbBatchExecution(FbConnection sqlConnection) : this(sqlConnection, null) { }
/// <summary> /// Creates an instance of FbBatchExecution engine. /// </summary> public FbBatchExecution() { this.sqlConnection = new FbConnection(); // do not specify the connection string this.connectionString = new FbConnectionStringBuilder(); }
internal FbTransaction(FbConnection connection, IsolationLevel il) { this.isolationLevel = il; this.connection = connection; }
/// <include file='Doc/en_EN/FbCommand.xml' path='doc/class[@name="FbCommand"]/constructor[@name="ctor(System.String,FbConnection)"]/*'/> public FbCommand(string cmdText, FbConnection connection) : this(cmdText, connection, null) { }
/// <include file='Doc/en_EN/FbDatabaseInfo.xml' path='doc/class[@name="FbDatabaseInfo"]/constructor[@name="ctor(FbConnection)"]/*'/> public FbDatabaseInfo(FbConnection connection) { this.connection = connection; }
/// <include file='Doc/en_EN/FbCommand.xml' path='doc/class[@name="FbCommand"]/constructor[@name="ctor(System.String,FbConnection,Transaction)"]/*'/> public FbCommand(string cmdText, FbConnection connection, FbTransaction transaction) : base() { this.parameters = new FbParameterCollection(); this.namedParameters = new StringCollection(); this.updatedRowSource = UpdateRowSource.Both; this.commandType = CommandType.Text; this.designTimeVisible = true; this.designTimeVisible = true; this.commandTimeout = 30; this.fetchSize = 200; this.commandText = ""; if (connection != null) { this.fetchSize = connection.ConnectionOptions.FetchSize; } if (cmdText != null) { this.CommandText = cmdText; } this.Connection = connection; this.transaction = transaction; }
/// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/method[@name="GetPooledConnectionCount(FbConnection)"]/*'/> public static int GetPooledConnectionCount(FbConnection connection) { FbPoolManager manager = FbPoolManager.Instance; FbConnectionPool pool = manager.FindPool(connection.ConnectionString); if (pool != null) { return pool.Count; } return 0; }
/// <include file='Doc/en_EN/FbCommand.xml' path='doc/class[@name="FbCommand"]/method[@name="Dispose(System.Boolean)"]/*'/> protected override void Dispose(bool disposing) { lock (this) { if (!this.disposed) { try { // If there are an active reader close it this.CloseReader(); // Release any unmanaged resources this.Release(); // release any managed resources if (disposing) { this.implicitTransaction = false; this.commandText = null; this.commandTimeout = 0; this.connection = null; this.transaction = null; this.parameters = null; this.namedParameters.Clear(); this.namedParameters = null; } this.disposed = true; } finally { base.Dispose(disposing); } } } }
/// <include file='Doc/en_EN/FbRemoteEvent.xml' path='doc/class[@name="FbRemoteEvent"]/constructor[@name="ctor(FbConnection)"]/*'/> public FbRemoteEvent(FbConnection connection) : this(connection, null) { }
public void SubsequentDeletes() { string selectSql = "SELECT * FROM test"; string deleteSql = "DELETE FROM test WHERE int_field = @id"; // Set up conenction and select/delete commands FbConnection connection = new FbConnection(this.Connection.ConnectionString); FbCommand select = new FbCommand(selectSql, connection); FbCommand delete = new FbCommand(deleteSql, connection); delete.Parameters.Add("@id", FbDbType.Integer); delete.Parameters[0].SourceColumn = "INT_FIELD"; // Set up the FbDataAdapter FbDataAdapter adapter = new FbDataAdapter(select); adapter.DeleteCommand = delete; // Set up dataset DataSet ds = new DataSet(); adapter.Fill(ds); // Delete one row ds.Tables[0].Rows[0].Delete(); adapter.Update(ds); // Delete another row ds.Tables[0].Rows[0].Delete(); adapter.Update(ds); // Delete another row ds.Tables[0].Rows[0].Delete(); adapter.Update(ds); }
/// <include file='Doc/en_EN/FbDataAdapter.xml' path='doc/class[@name="FbDataAdapter"]/constructor[@name="ctor(System.String,FbConnection)"]/*'/> public FbDataAdapter(string selectCommandText, FbConnection selectConnection) : base() { this.SelectCommand = new FbCommand(selectCommandText, selectConnection); }
private void Dispose(bool disposing) { lock (this) { if (!this.disposed) { try { // release any unmanaged resources if (this.transaction != null) { if ((this.transaction.State == TransactionState.TransactionStarted || this.transaction.State == TransactionState.TransactionPrepared) && !this.isUpdated) { this.transaction.Dispose(); this.transaction = null; } } // release any managed resources if (disposing) { this.connection = null; this.transaction = null; } } finally { this.isUpdated = true; this.disposed = true; } } } }
public override IDbConnection Open (out string errorMessage) { FbConnectionStringBuilder builder = null; try { if (settings.UseConnectionString) { builder = new FbConnectionStringBuilder (settings.ConnectionString); } else { builder = new FbConnectionStringBuilder (); builder.Database = settings.Database; builder.UserID = settings.Username; builder.Password = settings.Password; builder.Port = settings.Port; builder.DataSource = settings.Server; } builder.Pooling = settings.EnablePooling; builder.MinPoolSize = settings.MinPoolSize; builder.MaxPoolSize = settings.MaxPoolSize; connection = new FbConnection (builder.ToString ()); connection.Open (); errorMessage = String.Empty; isConnectionError = false; return connection; } catch { isConnectionError = true; errorMessage = String.Format ("Unable to connect. (CS={0})", builder == null ? "NULL" : builder.ToString ()); return null;
private void UpdateTransaction() { if (this.connection != null) { this.connection.InnerConnection.TransactionUpdated(); } this.isUpdated = true; this.connection = null; this.transaction = null; }
public void Disconnect() { try { this.db.Dispose(); this.owningConnection = null; this.options = null; this.lifetime = 0; this.pooled = false; this.db = null; this.DisposePreparedCommands(); } catch (IscException ex) { throw new FbException(ex.Message, ex); } }
internal FbTransaction(FbConnection connection) : this(connection, IsolationLevel.ReadCommitted) { }
public FbBatchExecution(FbConnection sqlConnection, FbScript isqlScript) { if (sqlConnection == null) { this.sqlConnection = new FbConnection(); // do not specify the connection string this.connectionString = new FbConnectionStringBuilder(); } else { this.sqlConnection = sqlConnection; this.connectionString = new FbConnectionStringBuilder(sqlConnection.ConnectionString); } if (isqlScript != null) { foreach (string sql in isqlScript.Results) { this.SqlStatements.Add(sql); } } }
internal FbDataReader( FbCommand command, FbConnection connection, CommandBehavior behavior) { this.position = STARTPOS; this.command = command; this.behavior = behavior; this.connection = connection; this.fields = this.command.GetFieldsDescriptor(); this.UpdateRecordsAffected(); }