【问题标题】:Retrieve Firebird ODS version in .Net在 .Net 中检索 Firebird ODS 版本
【发布时间】:2016-10-20 20:53:54
【问题描述】:

我正在使用 firebird Embedded v 2.5 和 .net FirebirdSql.Data.FirebirdClient。 我需要能够检索给定数据库的ODS 版本。

我试过了:

private string GetOds(FbConnection connection)
{
  using (var cmd = new FbCommand())
  {
    var sqlQuery = "select rdb$get_context('SYSTEM','ENGINE_VERSION') as version from RDB$DATABASE";
    cmd.CommandText = sqlQuery;
    cmd.Connection = connection;
    cmd.CommandType = CommandType.Text;

    using (var reader = cmd.ExecuteReader()) // HERE ITS WHERE THE EXCEPTION IS GENERATED.
    {
     ...
    }
  }
}

这会生成一个执行:{"Dynamic SQL Error\r\nSQL error code = -804\r\nFunction unknown\r\nRDB$GET_CONTEXT"}

【问题讨论】:

  • RDB$GET_CONTEXT 仅在数据库为 ODS 11.2 或更高版本时可用

标签: c# firebird firebird2.5 firebird-embedded firebird-.net-provider


【解决方案1】:

您可以使用FirebirdSql.Data.FirebirdClient.FbDatabaseInfo 类检索ODS 版本,它包装了FbConnection,可用于检索有关数据库的信息,例如:

using (var connection = new FbConnection(@"User=sysdba;Password=masterkey;Database=C:\path\to\your\database.fdb;DataSource=localhost"))
{
    connection.Open();
    var dbInfo = new FbDatabaseInfo(connection);

    Console.WriteLine("ODS Major: " + dbInfo.OdsVersion);
    Console.WriteLine("ODS Minor: " + dbInfo.OdsMinorVersion);
    Console.ReadLine();
}

这应该适用于 Firebird 支持的所有 ODS 版本,而 RDB$GET_CONTEXT 仅支持 ODS 11.2 或更高版本。

【讨论】:

    【解决方案2】:

    您可以从二进制文件中检索 ODS 版本。

    private const ushort FirebirdFlag = 0x8000;
    
    private void DispObsVersinoFromBinary(string path)
    {
        using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read))
        {
            int fileSize = (int)fs.Length;
            byte[] buf = new byte[1024];
            fs.Read(buf, 0, 1024);
            var obsHex = string.Join("", buf.Skip(0x12).Take(2).Select(x => x.ToString("X2")).Reverse());
            var minor = string.Join("", buf.Skip(0x40).Take(2).Select(x => x.ToString("X2")).Reverse());
            Console.WriteLine($"ODSVer:{Convert.ToInt32(obsHex, 16) & ~FirebirdFlag}");
            Console.WriteLine($"ODSMinorVer:{Convert.ToInt32(minor, 16)}");
        }
    }
    

    等模式
    https://github.com/kowill/Sample/blob/master/fb3test/Fb3Test/Program.cs#L71-L82

    【讨论】:

      猜你喜欢
      • 2011-02-18
      • 1970-01-01
      • 2016-03-17
      • 1970-01-01
      • 2015-01-17
      • 2023-03-15
      • 1970-01-01
      • 2013-01-15
      • 1970-01-01
      相关资源
      最近更新 更多