我正在尝试让Firebird Embedded在简单的.NET Core(2.1)控制台应用程序场景中工作。
我的项目文件如下:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="6.4.0" />
</ItemGroup>
</Project>
和Program.cs
像这样:
using System;
using System.IO;
using FirebirdSql.Data.FirebirdClient;
namespace Playground
{
class Program
{
static void Main(string[] args)
{
var workingDir = Directory.GetCurrentDirectory();
var dbPath = Path.Combine(workingDir, "Database.fdb");
var connString =
new FbConnectionStringBuilder
{
ClientLibrary = "libfbclient.dylib",
ServerType = FbServerType.Embedded,
UserID = "sysdba",
Database = dbPath
}
.ToString();
Console.WriteLine(connString);
FbConnection.CreateDatabase(connString, false);
var sql =
@"
CREATE TABLE my_table (
id int NOT NULL PRIMARY KEY,
name varchar(20) NOT NULL
);
";
using (var conn = new FbConnection(connString))
using (var cmd = new FbCommand(sql, conn))
{
conn.Open();
cmd.ExecuteNonQuery();
}
}
}
}
构建项目后(仅用dotnet build
),我将以下文件从Mac的二进制软件包(Firebird-3.0.4-33054-lipo-x86_64.pkg
)复制到输出目录(./bin/Debug/netcoreapp2.1
):
libfbclient.dylib
libib_util.dylib
libicudata.dylib
libicui18n.dylib
libicuuc.dylib
plugins (directory)
libEngine12.dylib
运行应用程序(dotnet MyApp.dll
)时出现异常:
Unhandled Exception: FirebirdSql.Data.FirebirdClient.FbException: Unable to complete network request to host "localhost".
Failed to establish a connection. ---> FirebirdSql.Data.Common.IscException: Unable to complete network request to host "localhost".
Failed to establish a connection.
at FirebirdSql.Data.Client.Native.FesDatabase.ProcessStatusVector(IntPtr[] statusVector) in C:\Users\Jiri\Documents\devel\NETProvider\working\Provider\src\FirebirdSql.Data.FirebirdClient\Client\Native\FesDatabase.cs:line 332
at FirebirdSql.Data.Client.Native.FesDatabase.CreateDatabase(DatabaseParameterBuffer dpb, String dataSource, Int32 port, String database, Byte[] cryptKey) in C:\Users\Jiri\Documents\devel\NETProvider\working\Provider\src\FirebirdSql.Data.FirebirdClient\Client\Native\FesDatabase.cs:line 171
at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.CreateDatabase(DatabaseParameterBuffer dpb) in C:\Users\Jiri\Documents\devel\NETProvider\working\Provider\src\FirebirdSql.Data.FirebirdClient\FirebirdClient\FbConnectionInternal.cs:line 125
at FirebirdSql.Data.FirebirdClient.FbConnection.CreateDatabaseImpl(String connectionString, Int32 pageSize, Boolean forcedWrites, Boolean overwrite) in C:\Users\Jiri\Documents\devel\NETProvider\working\Provider\src\FirebirdSql.Data.FirebirdClient\FirebirdClient\FbConnection.cs:line 101
--- End of inner exception stack trace ---
at FirebirdSql.Data.FirebirdClient.FbConnection.CreateDatabaseImpl(String connectionString, Int32 pageSize, Boolean forcedWrites, Boolean overwrite) in C:\Users\Jiri\Documents\devel\NETProvider\working\Provider\src\FirebirdSql.Data.FirebirdClient\FirebirdClient\FbConnection.cs:line 106
at Playground.Program.Main(String[] args) in /Users/anil/Temp/Playground/Program.cs:line 24
过去15年来,尽管仅在Windows上,我已经在许多场景(网络服务器,嵌入式)和不同技术(Delphi,.NET,.NET Core)中成功使用了Firebird。
有人能协助解决这个问题或将我指向可以自己进行RTFM解决的地方吗?