我正在使用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.
{
...
}
}
}
这将生成一个execption:{“动态SQL错误\ r \ nSQL错误代码= -804 \ r \ n函数未知\ r \ nRDB $ GET_CONTEXT”}
答案 0 :(得分:2)
您可以使用类<br />
检索ODS版本,它包装FirebirdSql.Data.FirebirdClient.FbDatabaseInfo
并可用于检索有关数据库的信息,例如:
FbConnection
这应该适用于Firebird支持的所有ODS版本,与仅在ODS 11.2或更高版本上支持的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();
}
相反。
答案 1 :(得分:0)
您可以从二进制文件中检索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