如何在 Mac OSX 上使用 Net.IBM.Data.Db2?

问题描述 投票:0回答:1

我有一个使用 Net.IBM.Data.Db2 的 dotnet 核心项目,它在 Windows 和 Linux 上运行良好。我现在尝试使用 Net.IBM.Data.Db2-osx 在 Apple Macbook M3 Pro 上运行它,但出现以下运行时错误:

System.IO.FileNotFoundException: Could not load file or assembly 'IBM.Data.Db2, Version=8.0.0.200, Culture=neutral, PublicKeyToken=7c307b91aa13d208'. The system cannot find the file specified.

我的控制台应用程序包含以下代码。

ConsoleApp1.csproj:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Dapper" Version="2.1.37" />
        <!-- <PackageReference Include="Net.IBM.Data.Db2" Version="8.0.0.200" Condition="$([MSBuild]::IsOsPlatform('Windows'))" /> -->
        <!-- <PackageReference Include="Net.IBM.Data.Db2-lnx" Version="8.0.0.200" Condition="$([MSBuild]::IsOsPlatform('Linux'))" /> -->
        <!-- <PackageReference Include="Net.IBM.Data.Db2-osx" Version="8.0.0.200" Condition="$([MSBuild]::IsOsPlatform('OSX'))" /> -->
        <PackageReference Include="Net.IBM.Data.Db2-osx" Version="8.0.0.200" />
</ItemGroup>

</Project>

程序.cs:

// See https://aka.ms/new-console-template for more information
using IBM.Data.Db2; // note: this is correct, Net.IBM.Data.Db2 does not work
using Dapper;
using System.Data;

Console.WriteLine("Start");

string CONNECTION_STRING = "Server=db.foo.com:50000;Database=foo;UID=foo;PWD=bar;";

var sql = "select * from ST004.students";
using (var connection = new DB2Connection(CONNECTION_STRING))
{
    var rows = await connection.QueryAsync(sql);
    Console.WriteLine(rows);
}

Console.WriteLine("End");

上面抛出以下运行时错误:

Exception has occurred: CLR/System.IO.FileNotFoundException
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in System.Private.CoreLib.dll: 'Could not load file or assembly 'IBM.Data.Db2, Version=8.0.0.200, Culture=neutral, PublicKeyToken=7c307b91aa13d208'. The system cannot find the file specified.'
   at Program.<<Main>$>d__0.MoveNext() in /Users/me/dev/ConsoleApp1/ConsoleApp1/Program.cs:line 17
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at Program.<Main>$(String[] args) in /Users/me/dev/ConsoleApp1/ConsoleApp1/Program.cs:line 6
   at Program.<Main>(String[] args)
c# .net macos db2
1个回答
0
投票

目前,arm64 上没有对 IBM Data.Db2 的本机支持。您可能需要 docker 容器/VM 来运行您的项目。

© www.soinside.com 2019 - 2024. All rights reserved.