How to close a connection with a firebird database(如何关闭与 firebird 数据库的连接)
问题描述
我正在使用 asp.net c# webforms framework 4.5 开发一个项目,我对 Firebird 数据库进行了连接测试,但是当我关闭此连接时它并没有关闭,我使用以下代码来完成它:
I'm developing a project using asp.net c# webforms framework 4.5, and I did a connection test on Firebird database, but when I close this connection it isn't closing, I used the following code to do it:
string conDDNS;
FbConnection conexaoDDNS;
protected void Abrir_Fechar_Click(object sender, EventArgs e)
{
try
{
this.conDDNS = "DRIVER=InterBase/Firebird(r) driver;User=SYSDBA;Password=masterkey;Database=localhost:C:/AdCom/ADCOM.FDB";
this.conexaoDDNS = new FbConnection(conDDNS);
this.conexaoDDNS.Open();
ListItem item = new ListItem("Conexão aberta");
ListBox1.Items.Add(item);
this.conexaoDDNS.Dispose();
this.conexaoDDNS.Close();
ListItem item2 = new ListItem("Conexão fechada");
ListBox1.Items.Add(item2);
}
catch (Exception erro)
{
ListItem item = new ListItem(erro.ToString());
ListBox1.Items.Add(item);
}
}
我已经使用了 .Close() 和 .Dispose() 命令,但是没有用.
I have already used the .Close() and .Dispose() command but it didn't work.
当我做这个调试时,我意识到当它通过 .Open() 命令时,它会打开连接,没关系.但是当它通过 .Close() 命令时,连接仍然在数据库上打开.
When I did this debugging I realized that when it pass by .Open()command it opens the connection, that is alright. But when it pass by .Close() command the connection is still open on database.
要知道在数据库上打开的连接数,我使用以下命令:
To know the number of connections opened on database I'm using the following command:
select * FROM MON$ATTACHMENTS
推荐答案
Firebird .NET 提供程序有一个内置的连接池,默认情况下它是启用的.您可以将 Pooling=false 添加到连接字符串以禁用它.但是,在很多情况下,连接池是一件好事(它可以节省必须打开连接的时间),因此请确保您确实需要禁用它.
The Firebird .NET provider has a built-in connection pool and it is enabled by default. You can add Pooling=false to the connection string to disable it. However in a lot of cases a connection pool is a good thing (it saves the time of having to open a connection), so make sure you really need to disable it.
调用 FbConnection.ClearPool(connection) 或 FbConnection.ClearAllPools() 应该关闭池中当前打开的连接.
Calling FbConnection.ClearPool(connection) or FbConnection.ClearAllPools() should close currently open connections in the pool.
还要确保在查询MON$ATTACHMENTS 时开始一个新事务.监控表的内容在单个事务中冻结".
Also make sure you start a new transaction when querying MON$ATTACHMENTS. The content of monitoring tables is 'frozen' inside a single transaction.
这篇关于如何关闭与 firebird 数据库的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何关闭与 firebird 数据库的连接
基础教程推荐
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- WPF 模态进度窗口 2022-01-01
