FirebirdSql.Data.FirebirdClient 与 Sysdba 以外的用户连接 - 未定义用户名和密码

FirebirdSql.Data.FirebirdClient connecting with a user other than Sysdba - username and password are not defined

我使用 FirebirdSql.Data.FirebirdClient 连接到 Firebird 数据库(WPF 桌面应用程序)。

服务器版本:WI-V3.0.5.33220 Firebird 3.0,ADO.net提供程序版本为 7.5.0 (NuGet)

我创建了一个除 SYSDBA 之外的用户,该用户仅对表具有只读访问权限(仅 SELECT)。对于这个新用户,与 FlameRobin 的连接没有问题。但是,当我在 FbConnectionStringBuilder class 中指定这个新用户和相应的只读角色时,我得到一个

“您的用户名和密码未定义”

错误。如果我用 SYSDBA 和相应的密码替换新用户,则连接正常。

using FirebirdSql.Data.FirebirdClient;

namespace Test
{
    class DBConnection
    {
        FbConnection fbConnection;
        public void CreateConnection() 
        {
            FbConnectionStringBuilder builder = new FbConnectionStringBuilder();
            builder.Charset = "WIN1252";
            builder.Database = "firebird2:DB_NAME";
            builder.Dialect = 3;
            builder.Role = "READ_ONLY_OTN";
            builder.UserID = "TEST";
            builder.Password = "Test";
            builder.ServerType = FbServerType.Default;
            fbConnection = new FbConnection(builder.ConnectionString);
            fbConnection.Open();
        }
    }
}

除了密码错误之外,还有什么可能导致此错误(我检查了两次并使用 FlameRobin)?

问题是,当连接到 Firebird 3 时,Firebird ADO.net 提供程序 (FirebirdSql.Data.FirebirdClient) 仅支持新的 SRP 身份验证插件,而不支持 Legacy_Auth 身份验证插件。如果您的用户是使用 Legacy_UserManager 创建的,则您无法使用 Firebird ADO.net 提供程序进行身份验证。您需要使用 Srp.

创建用户

根据您的具体 Firebird 配置,您需要将 Srp 添加到 UserManager 配置列表,然后创建用户:

create user <youruser> password '<password>' using plugin srp;

出于安全原因,我建议您删除使用 Legacy_UserManager:

创建的用户
drop user <youruser> using plugin legacy_usermanager;

我还建议您从 UserManager 列表中删除 Legacy_UserManager,或者确保 Srp 在列表中排在第一位,以避免意外创建安全性较低的用户用户管理器(执行不带 using plugin <plugin> 子句的 SQL 用户管理语句将默认为列表中的第一个用户管理器)。