【问题标题】:The type 'System.Data.Common.DbTransaction' is defined in an assembly that is not referenced. You must add a reference to assembly“System.Data.Common.DbTransaction”类型是在未引用的程序集中定义的。您必须添加对程序集的引用
【发布时间】:2014-05-19 17:58:47
【问题描述】:

欢迎。我正在尝试在 Windows mobile 6 上编写一个连接到 Firebird 2.5.2 数据库的应用程序(使用 Visual Studio 2008 和 Forms)。我写了这段代码:

  static public void Execute(FbTransaction tr, string sql, bool commit)
    {
        FbConnection cn = null;
        FbCommand cmd = null;

        if (tr != null)
        {
            cmd = new FbCommand(sql, tr.Connection, tr);
        }
        else
        {
            cn = new FbConnection(ConnString());
            cmd = new FbCommand(sql, cn);
        }

        if (cmd.Connection.State == ConnectionState.Closed)
        {
            cmd.Connection.Open();
        }

        cmd.ExecuteNonQuery();

        cmd.Dispose();

        if (cn != null)
        {
            cn.Close();
            cn.Dispose();
        }
    }

我在第 1 车道出现错误(执行突出显示)

错误 1 ​​类型“System.Data.Common.DbTransaction”在 未引用的程序集。您必须添加对程序集的引用 'System.Data,版本=2.0.0.0,文化=中性, PublicKeyToken=b77a5c561934e089'。

我已将 System.Data 版本 2.0.0.0 添加到我的参考资料中。将不胜感激。


我找到了解决方案。对于那些将来会面临类似问题的人,我是这样做的: 要让它在 VS 2008 (.net 3.5) 和 firebird 2.5.2 (目前最新) 中使用 64 位 windows 窗体,您需要做的第一件事是下载 Firebird EMBEDED win x 64 包http://www.firebirdsql.org/en/firebird-2-5-2-upd1/

接下来,选择 .NET 提供程序的源代码版本,对我来说是这个(如果你在 VS2010 或更高版本中编写代码,请尝试更新版本) http://sourceforge.net/projects/firebird/files/firebird-net-provider/2.5.2/

打开它,然后在配置管理器中在 x64 下编译它。 (记得为特定的.net版本添加对System.Data的引用,我想我用的是2.0.0.0)

现在,创建您想要的 winform 项目,并包含您在步骤 1 中下载的嵌入式 Firebird 包中的所有 .dll(将现有项目添加到项目的根目录)

添加对新编译的 FirebirdSql.dll 的引用,我在我的 \NETProvider-2.5.2-src\NETProvider\source\FirebirdSql\Data\bin\x64\Debug\FirebirdSql.Data.FirebirdClient.dll

然后享受。奖金 ->

本地 Firebird 服务器的字符串路径很棘手,所以这对我有用

     string Firebird_path = "User=SYSDBA;Password=masterkey;" +
           "Database=localhost:L:\\DBS\\DBS.FDB; " +
           "DataSource=localhost;Charset=NONE;";

【问题讨论】:

  • 你在哪里使用 DbTransaction?我在您发布的代码中找不到它。
  • 您使用哪个 .Net Framework 版本?从 2.0 开始,所有版本都应该支持 DbTransaction,但你永远不知道...
  • 我使用 .Net 3.0,不,我从不使用 DbTransaction。

标签: c# windows-mobile firebird2.5


【解决方案1】:

您是否在项目中引用了 Firebird .NET 提供程序?

您可以找到它here。它也可以作为 NuGet 包添加。

【讨论】:

  • 是的,我有 -> 我的意思是为 FirebirdSql.Data.FireBirdClient 和 FirebirdSql.Data.UnitTests 添加 ref,包中没有更多内容。
  • 最后是手动编译正确的包并使用嵌入式 FirebirdServer 的问题。对于以后遇到这个问题的人,我已经编辑了原帖。
  • 感谢您接受答案并分享解决方案!
【解决方案2】:

FbTransaction 类实现了DbTranaction 接口。这意味着如果你在代码中使用FbTransaction,那么在运行时也需要加载这个接口,所以你需要引用程序集。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 2019-06-28
    • 1970-01-01
    相关资源
    最近更新 更多