Example #1
0
        public void ConnectionPoolingTest()
        {
            // Using ActiveUsers as proxy for number of connections
            FbConnectionStringBuilder csb = BuildConnectionStringBuilder();

            csb.Pooling            = true;
            csb.ConnectionLifeTime = 5;
            string cs = csb.ToString();

            FbConnection myConnection1 = new FbConnection(cs);
            FbConnection myConnection2 = new FbConnection(cs);

            int active = ActiveConnections();

            // 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();

            Assert.AreEqual(active + 2, ActiveConnections());

            // Clear pools
            FbConnection.ClearAllPools();
        }
Example #2
0
    public async Task ConnectionPoolingLifetimeTest()
    {
        FbConnection.ClearAllPools();
        var csb = BuildConnectionStringBuilder(ServerType, Compression, WireCrypt);

        csb.Pooling            = true;
        csb.ConnectionLifeTime = 5;
        var cs = csb.ToString();

        var active = await GetActiveConnections();

        await using (FbConnection
                     myConnection1 = new FbConnection(cs),
                     myConnection2 = new FbConnection(cs))
        {
            await myConnection1.OpenAsync();

            await myConnection2.OpenAsync();

            Assert.AreEqual(active + 2, await GetActiveConnections());
        }

        Thread.Sleep(TimeSpan.FromSeconds(csb.ConnectionLifeTime * 2));
        Assert.AreEqual(active, await GetActiveConnections());
    }
Example #3
0
        public void ConnectionPoolingMinPoolSizeTest()
        {
            FbConnectionStringBuilder csb = BuildConnectionStringBuilder();

            csb.Pooling            = true;
            csb.ConnectionLifeTime = 5;
            csb.MinPoolSize        = 3;
            string cs = csb.ToString();

            int active = ActiveConnections();

            var connections = new List <FbConnection>();

            try
            {
                for (int i = 0; i < csb.MinPoolSize * 2; i++)
                {
                    var connection = new FbConnection(cs);
                    Assert.DoesNotThrow(() => connection.Open());
                    connections.Add(connection);
                }
            }
            finally
            {
                connections.ForEach(x => x.Dispose());
            }

            System.Threading.Thread.Sleep(csb.ConnectionLifeTime * 2 * 1000);

            Assert.AreEqual(active + csb.MinPoolSize, ActiveConnections());

            FbConnection.ClearAllPools();
        }
Example #4
0
        public static void DropDatabase(string connectionString)
        {
            FbConnection.ClearAllPools();

            // Avoid "lock time-out on wait transaction" exception
            var retries = 5;

            while (true)
            {
                try
                {
                    FbConnection.DropDatabase(connectionString);
                    break;
                }
                catch
                {
                    if (--retries == 0)
                    {
                        throw;
                    }
                    else
                    {
                        Thread.Sleep(100);
                    }
                }
            }
        }
Example #5
0
        public void ConnectionPoolingTimeOutTest()
        {
            // Using ActiveUsers as proxy for number of connections
            FbConnectionStringBuilder csb = BuildConnectionStringBuilder();

            csb.Pooling            = true;
            csb.ConnectionLifeTime = 5;
            string cs = csb.ToString();

            int active = ActiveConnections();

            using (FbConnection
                   myConnection1 = new FbConnection(cs),
                   myConnection2 = new FbConnection(cs))
            {
                myConnection1.Open();
                myConnection2.Open();

                Assert.AreEqual(active + 2, ActiveConnections());

                myConnection1.Close();
                myConnection2.Close();
            }

            System.Threading.Thread.Sleep(csb.ConnectionLifeTime * 2 * 1000);

            Assert.AreEqual(active, ActiveConnections());

            FbConnection.ClearAllPools();
        }
Example #6
0
 public static FbConnection getConnection()
 {
     try
     {
         if (conn == null)
         {
             conn = new FbConnection(strConn);
             conn.Open();
             return(conn);
         }
         else
         {
             if (conn.State == System.Data.ConnectionState.Open)
             {
                 return(conn);
             }
             else
             {
                 FbConnection.ClearAllPools();
                 conn = new FbConnection(strConn);
                 conn.Open();
                 return(conn);
             }
         }
     }
     catch (Exception excep)
     {
         MessageBox.Show("Erro - " + excep.Message);
         return(null);
     }
 }
    public async Task DNET595_ProperConnectionPoolConnectionsClosing()
    {
        FbConnection.ClearAllPools();
        const int NumberOfThreads = 15;

        var csb = BuildConnectionStringBuilder(ServerType, Compression, WireCrypt);

        csb.Pooling            = true;
        csb.ConnectionLifeTime = 5;
        csb.MinPoolSize        = 0;
        var cs = csb.ToString();

        var active = await GetActiveConnections();

        var tasks = new List <Task>();

        for (var i = 0; i < NumberOfThreads; i++)
        {
            tasks.Add(GetSomethingLoopHelper(cs, 50));
        }
        await Task.WhenAll(tasks);

        Assert.Greater(await GetActiveConnections(), active);

        var sw = new Stopwatch();

        sw.Start();
        while (sw.Elapsed.TotalSeconds < 60)
        {
            await GetSomethingHelper(cs);
        }

        Thread.Sleep(TimeSpan.FromSeconds(csb.ConnectionLifeTime * 2));
        Assert.AreEqual(active, await GetActiveConnections());
        public void ConnectionPoolingMaxPoolSizeTest()
        {
            FbConnection.ClearAllPools();
            FbConnectionStringBuilder csb = BuildConnectionStringBuilder(FbServerType, Compression);

            csb.Pooling            = true;
            csb.ConnectionLifeTime = 120;
            csb.MaxPoolSize        = 10;
            string cs = csb.ToString();

            var connections = new List <FbConnection>();

            try
            {
                for (int i = 0; i <= csb.MaxPoolSize; i++)
                {
                    var connection = new FbConnection(cs);
                    connections.Add(connection);
                    if (i == csb.MaxPoolSize)
                    {
                        Assert.Throws <InvalidOperationException>(() => connection.Open());
                    }
                    else
                    {
                        Assert.DoesNotThrow(() => connection.Open());
                    }
                }
            }
            finally
            {
                connections.ForEach(x => x.Dispose());
            }
        }
        public virtual void TearDown()
        {
            string cs = BuildConnectionString(_fbServerType);

            if (_withTransaction)
            {
                try
                {
                    if (!_transaction.IsUpdated)
                    {
                        _transaction.Commit();
                    }
                }
                catch
                {
                }
                try
                {
                    _transaction.Dispose();
                }
                catch
                {
                }
            }
            if (_connection != null)
            {
                _connection.Dispose();
            }
            DeleteAllData(cs);
            FbConnection.ClearAllPools();
        }
Example #10
0
        public void TearDown()
        {
            FbConnection.ClearAllPools();

            // Avoid "lock time-out on wait transaction" exception
            var retries = 5;

            while (true)
            {
                try
                {
                    FbConnection.DropDatabase(IntegrationTestOptions.Firebird.ConnectionString);
                    break;
                }
                catch
                {
                    if (--retries == 0)
                    {
                        throw;
                    }
                    else
                    {
                        Thread.Sleep(100);
                    }
                }
            }
        }
Example #11
0
        public virtual void TearDown()
        {
            string cs = BuildConnectionString(FbServerType, Compression);

            _connection.Dispose();
            DeleteAllData(cs);
            FbConnection.ClearAllPools();
        }
Example #12
0
 public void ExecuteProcedureBusq()
 {
     _Comand.ExecuteNonQuery();
     _Conect.Close();
     _Conect.Dispose();
     //  FbConnection.ClearPool(_Conect);
     FbConnection.ClearAllPools();
 }
Example #13
0
 public void FbConeccionPrincipal()
 {
     _Conect = new FbConnection();
     // _Conect.ConnectionString = "User=SYSDBA;password=masterkey;DataSource=localhost;Database=BDCrmPtics;Charset=NONE;Dialect=3;Max Pool Size=1024;";
     _Conect.ConnectionString = "User=SYSDBA;password=masterkey;DataSource=localhost;pooling=false;port=3050;Database=181.129.170.198:BDCrmPtics;Charset=NONE;Dialect=3;Max Pool Size=1024;";
     FbConnection.ClearPool(_Conect);
     FbConnection.ClearAllPools();
 }
 private void dropDbSchema()
 {
     if (_sessionFactory.ConnectionProvider.Driver is FirebirdClientDriver)
     {
         // necessary firebird hack to be able to drop used tables
         FbConnection.ClearAllPools();
     }
     new SchemaExport(Cfg).Drop(false, true);
 }
Example #15
0
 public void TearDown()
 {
     FbConnection.ClearAllPools();
     foreach (var item in _initalized)
     {
         Drop(item.Item1, item.Item2);
     }
     _initalized.Clear();
 }
Example #16
0
 //============================================================================
 /// <summary>
 /// Closes the reader and the connection.
 /// </summary>
 //============================================================================
 public override void closeConnection()
 {
     if (reader != null)
     {
         reader.Close();
     }
     fbConn.Close();
     FbConnection.ClearAllPools();
 }
Example #17
0
 private void F_UTILITARIOBANCO_Load(object sender, EventArgs e)
 {
     using (ClassAguarde carregando = new ClassAguarde())
     {
         Conexao.CarregaConfXml();
         bancoOriginal = Conexao.SERVER + Conexao.BANCO;
     }
     FbConnection.ClearAllPools();
 }
Example #18
0
 public void TearDown()
 {
     FbConnection.ClearAllPools();
     foreach (var item in _initalized)
     {
         var cs = FbTestsBase.BuildConnectionString(item.Item1, item.Item2);
         FbConnection.DropDatabase(cs);
     }
     _initalized.Clear();
 }
Example #19
0
 public void DeleteDatabase()
 {
     if (!deleted)
     {
         //File.Delete(dbName);
         FbConnection.ClearAllPools();
         FbConnection.DropDatabase(Connection.ConnectionString);
         deleted = true;
     }
 }
        public virtual async Task TearDown()
        {
            var cs = BuildConnectionString(ServerType, Compression, WireCrypt);

            _connection.Dispose();
            if (_insertTestData)
            {
                await DeleteAllData(cs);
            }
            FbConnection.ClearAllPools();
        }
Example #21
0
 public override void After(MethodInfo methodUnderTest)
 {
     try
     {
         FbConnection.ClearAllPools();
     }
     finally
     {
         Monitor.Exit(GlobalLock);
     }
 }
Example #22
0
        private static void DropDatabase()
        {
            FbConnection.ClearAllPools();

            var connectionStringBuilder = new FbConnectionStringBuilder(ConnectionUtils.GetConnectionString());

            if (File.Exists(connectionStringBuilder.Database))
            {
                FbConnection.DropDatabase(connectionStringBuilder.ConnectionString);
            }
        }
Example #23
0
        public virtual void TearDown()
        {
            var cs = BuildConnectionString(FbServerType, Compression);

            _connection.Dispose();
            if (_insertTestData)
            {
                DeleteAllData(cs);
            }
            FbConnection.ClearAllPools();
        }
Example #24
0
 private void buttonRealizaRestauração_Click(object sender, EventArgs e)
 {
     if (textBoxArquivoRestauracao.Text == "")
     {
         Mensagem.Aviso(this, "É necessário selecionar o arquivo de backup para que seja possível realizar a restauração !");
         return;
     }
     FbConnection.ClearAllPools();
     bloqueiaFechamento = true;
     RealizandoRestore(@textBoxArquivoRestauracao.Text, true);
     bloqueiaFechamento = false;
 }
Example #25
0
        //============================================================================
        /// <summary>
        /// Create the Firebird database
        /// </summary>
        /// <param name="dbName"></param>
        /// <returns>True if it was created</returns>
        //============================================================================
        protected bool CreateBlankDB(string dbName)
        {
            bool created = false;

            if (!File.Exists(dbName))
            {
                FbConnection.CreateDatabase("Database=" + dbName + ";" + FServerType);
                FbConnection.ClearAllPools();
                created = true;
            }
            return(created);
        }
Example #26
0
        public PersistenceEngineFixture()
        {
            FbConnection.ClearAllPools();
            FbConnection.CreateDatabase(ConnectionString, true);

            _createPersistence =
                pageSize =>
                new FirebirdSqlPersistenceFactory(
                    new FirebirdInProcessConnectionFactory(ConnectionString),
                    new BinarySerializer(),
                    new FirebirdSqlDialect(),
                    pageSize: pageSize,
                    streamIdHasher: new StreamIdHasher <SHA256>()).Build();
        }
Example #27
0
        private void buttonRealizaBackup_Click(object sender, EventArgs e)
        {
            if (textBoxArquivoBackup.Text == "")
            {
                Mensagem.Aviso(this, "É necessário selecionar o local do arquivo de backup para que seja possível realizar o backup !");
                return;
            }
            FbConnection.ClearAllPools();

            BloqueiaControlesBackup();
            bloqueiaFechamento = true;
            RealizandoBackup(@textBoxArquivoBackup.Text, true);
            bloqueiaFechamento = false;
            BloqueiaControlesBackup();
        }
Example #28
0
        public void SetUp()
        {
            if (System.IO.File.Exists("fbtest.fdb"))
            {
                FbConnection.ClearAllPools();
                FbConnection.DropDatabase(IntegrationTestOptions.Firebird.ConnectionString);
            }

            FbConnection.CreateDatabase(IntegrationTestOptions.Firebird.ConnectionString);

            _connection = new FbConnection(IntegrationTestOptions.Firebird.ConnectionString);
            _processor  = MakeProcessor();
            _connection.Open();
            _processor.BeginTransaction();
        }
        public void DNET595_ProperConnectionPoolConnectionsClosing()
        {
            FbConnection.ClearAllPools();
            const int NumberOfThreads = 15;

            FbConnectionStringBuilder csb = BuildConnectionStringBuilder(FbServerType);

            csb.Pooling            = true;
            csb.ConnectionLifeTime = 5;
            csb.MinPoolSize        = 0;
            string cs = csb.ToString();

            var active = GetActiveConnections();

            var threads = new List <Thread>();

            for (int i = 0; i < NumberOfThreads; i++)
            {
                var t = new Thread(o =>
                {
                    for (int j = 0; j < 50; j++)
                    {
                        GetSomething(cs);
                    }
                });
                t.IsBackground = true;
                t.Start();
                threads.Add(t);
            }
            foreach (var thread in threads)
            {
                thread.Join();
            }

            Assert.Greater(GetActiveConnections(), active);

            var sw = new Stopwatch();

            sw.Start();
            while (sw.Elapsed.TotalSeconds < 60)
            {
                GetSomething(cs);
            }

            Thread.Sleep(TimeSpan.FromSeconds(csb.ConnectionLifeTime * 2));
            Assert.AreEqual(active, GetActiveConnections());
        }
Example #30
0
        public static void Restore(string DBFilePath, string BackupFilePath, string DbID, string DbPassword)
        {
            //db커낵션 확인후 커넥션 끊고 기존db파일 이름 바꿈
            try
            {
                //커넥션 스트링 작성
                FbConnectionStringBuilder fsb = new FbConnectionStringBuilder();
                fsb.Database   = DBFilePath;
                fsb.UserID     = DbID;
                fsb.Password   = DbPassword;
                fsb.ServerType = FbServerType.Embedded;
                //커넥션풀 클리어
                FbConnection.ClearAllPools();
                //원본 DB파일 이름 변경(원본파일 유지 해야 되니까)
                if (File.Exists(DBFilePath))
                {
                    string dbFolder  = DBFilePath.Substring(DBFilePath.LastIndexOf("\\") + 1);
                    string oldDbPath = string.Format
                                       (
                        "{0}\\old_{1}{2}{3}{4}{5}{6}.fdb",
                        dbFolder,
                        DBFilePath.Substring(DBFilePath.LastIndexOf("\\") + 1).Replace(".fdb", string.Empty),
                        DateTime.Now.Year.ToString().Substring(2),
                        DateTime.Now.Month.ToString().PadLeft(2, '0'),
                        DateTime.Now.Day.ToString().PadLeft(2, '0'),
                        DateTime.Now.Hour.ToString().PadLeft(2, '0'),
                        DateTime.Now.Minute.ToString().PadLeft(2, '0')
                                       );
                    File.Move(DBFilePath, oldDbPath);
                }

                //백업 파일 객체 생성
                FbBackupFile bkFile = new FbBackupFile(BackupFilePath);
                //위의 백업파일로부터 복구시작
                FbRestore restore = new FbRestore();
                restore.BackupFiles.Add(bkFile);
                restore.Options          = FbRestoreFlags.Create;
                restore.ConnectionString = fsb.ToString();
                restore.Execute();
            }
            catch (Exception)
            {
                throw;
            }
        }