这是一个朋友的小项目,其目标是从给定的 firebird 数据库文件中读取数据并将其放入 MS Office 2010 模板中......所以 Firebird 作为数据库后端和 .NET 4.x 项目类型的办公室都是给定的堆栈。
我编写了一个小型(控制台)测试应用程序来与 firebird 嵌入式数据库客户端取得联系,并且已经遇到了我没有摆脱的第一个问题。我的代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FirebirdSql.Data.FirebirdClient;
namespace TestFirebirdConnection
{
class Program
{
static void Main(string[] args)
{
// Set the ServerType to 1 for connect to the embedded server
string connectionString =
"User=sysdba;" +
"Password=******;" +
"Database=C:\\...\\...\\...\\PDATA.FDB;" +
"ServerType=1;" +
"Charset=NONE;";
try
{
FbConnection dbConnection = new FbConnection(connectionString);
dbConnection.Open();
string SQLCommandText = "select * from Patients";
FbCommand dbCommand = new FbCommand(SQLCommandText, dbConnection);
FbDataReader dr = dbCommand.ExecuteReader();
while (dr.Read())
{
Console.WriteLine(dr["TITLE"] + " " + dr["SURNAME"] + " " + dr["NAME"]);
}
dr.Close();
dbConnection.Close();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
一切正常,代码在外壳上显示患者数据库的所有名称。我已经使用调试器检查了 datareader 和 dbConnection 是否正确关闭(),就是这种情况。
在最后一行之后,我每次都会收到一条令人讨厌的 Windows 错误消息(那种内存访问冲突),我不知道为什么会发生这种情况。
更新:看来,它与 fbintl.dll 有关
更新 2:如果我连接到 firebird 服务器,则不会发生这种情况(不幸的是,这对于我的轻量级办公室模板项目来说不是一个好的解决方案)
有人知道为什么会这样吗?
我在用:
- Firebird ADO.NET Provider 4.6(来自 NuGet)
- Firebird 嵌入式数据库 2.5.3 x64
我实际上不确定数据库文件是用哪个版本的火鸟创建的