服务帐户在 NServiceBus 启动时抛出 SQLiteException

发布于 2024-10-16 14:07:59 字数 3735 浏览 1 评论 0 原文

当我尝试使用服务帐户凭据启动 nservicebus.host.exe 时,出现以下异常:

    Database was not configured through Database method.  
System.Data.SQLite.SQLiteException: Unable to open the database file  
at System.Data.SQLite.SQLite3.Open(String strFilename, SQLiteOpenFlagsEnum flags, Int32 maxPoolSize, Boolean usePool)  
at System.Data.SQLite.SQLiteConnection.Open()
at NHibernate.Connection.DriverConnectionProvider.GetConnection() in :line 0
at NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare() in :line 0
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper) in :line 0
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory) in :line 0
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) in :line 0
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in D:\dev\fluent-nhibernate\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 93
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in D:\dev\fluent-nhibernate\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 100
at NServiceBus.SagaPersisters.NHibernate.Config.Internal.SessionFactoryBuilder.Build(IDictionary^2 nhibernateProperties, Boolean updateSchema) in c:\Dev\DotNet\NServiceBus\src\impl\SagaPersisters\NHibernateSagaPersister\NServiceBus.SagaPersisters.NHibernate.Config\Internal\SessionFactoryBuilder.cs:line 48
--- End of inner exception stack trace ---
at NServiceBus.SagaPersisters.NHibernate.Config.Internal.SessionFactoryBuilder.Build(IDictionary^2 nhibernateProperties, Boolean updateSchema) in c:\Dev\DotNet\NServiceBus\src\impl\SagaPersisters\NHibernateSagaPersister\NServiceBus.SagaPersisters.NHibernate.Config\Internal\SessionFactoryBuilder.cs:line 55
at NServiceBus.ConfigureNHibernateSagaPersister.NHibernateSagaPersister(Configure config, IDictionary^2 nhibernateProperties, Boolean autoUpdateSchema) in c:\Dev\DotNet\NServiceBus\src\impl\SagaPersisters\NHibernateSagaPersister\NServiceBus.SagaPersisters.NHibernate.Config\ConfigureNHibernateSagaPersister.cs:line 80
at Ibfx.BackOffice.Services.NewAccounts.NewAccountsEndpoint.Init() in C:\Dev\TFS\Omega\Src\Svcs\NewAccounts\Src\Service\NewAccountsEndpoint.cs:line 67
at NServiceBus.Host.Internal.GenericHost.Start() in c:\Dev\DotNet\NServiceBus\src\host\NServiceBus.Host\Internal\GenericHost.cs:line 56

如果我使用自己的帐户运行主机,则一切正常,但如果我使用域凭据将主机作为服务运行或使用这些凭据与 RunAs 命令相同的凭据我得到上述异常。我需要配置哪些权限才能使服务正常运行?

这是我的配置:

        var configure = NServiceBus.Configure.With()
            .Log4Net<Log4NetLoggerAdapter>(a => { })
            .UnityBuilder(container)
            .XmlSerializer()
            .RijndaelEncryptionService()
            .MsmqTransport()
                .IsTransactional(false)
                .PurgeOnStartup(false)
                .MsmqSubscriptionStorage();

        configure.Configurer.ConfigureComponent<MsmqSubscriptionStorage>(
                    ComponentCallModelEnum.None).ConfigureProperty(p => p.DontUseExternalTransaction
                    , true
                );

        IBus bus = configure.UnicastBus()
            .ImpersonateSender(true)
            .LoadMessageHandlers()
            .Sagas()
            .NHibernateSagaPersister()
        .CreateBus()
        .Start();

我有一个 NServiceBus.Host.exe.config 文件,其中包含以下内容:

<配置> <启动useLegacyV2RuntimeActivationPolicy =“true”>

I'm getting the following exception when I try to start nservicebus.host.exe with service account credentials:

    Database was not configured through Database method.  
System.Data.SQLite.SQLiteException: Unable to open the database file  
at System.Data.SQLite.SQLite3.Open(String strFilename, SQLiteOpenFlagsEnum flags, Int32 maxPoolSize, Boolean usePool)  
at System.Data.SQLite.SQLiteConnection.Open()
at NHibernate.Connection.DriverConnectionProvider.GetConnection() in :line 0
at NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare() in :line 0
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper) in :line 0
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory) in :line 0
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) in :line 0
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in D:\dev\fluent-nhibernate\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 93
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in D:\dev\fluent-nhibernate\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 100
at NServiceBus.SagaPersisters.NHibernate.Config.Internal.SessionFactoryBuilder.Build(IDictionary^2 nhibernateProperties, Boolean updateSchema) in c:\Dev\DotNet\NServiceBus\src\impl\SagaPersisters\NHibernateSagaPersister\NServiceBus.SagaPersisters.NHibernate.Config\Internal\SessionFactoryBuilder.cs:line 48
--- End of inner exception stack trace ---
at NServiceBus.SagaPersisters.NHibernate.Config.Internal.SessionFactoryBuilder.Build(IDictionary^2 nhibernateProperties, Boolean updateSchema) in c:\Dev\DotNet\NServiceBus\src\impl\SagaPersisters\NHibernateSagaPersister\NServiceBus.SagaPersisters.NHibernate.Config\Internal\SessionFactoryBuilder.cs:line 55
at NServiceBus.ConfigureNHibernateSagaPersister.NHibernateSagaPersister(Configure config, IDictionary^2 nhibernateProperties, Boolean autoUpdateSchema) in c:\Dev\DotNet\NServiceBus\src\impl\SagaPersisters\NHibernateSagaPersister\NServiceBus.SagaPersisters.NHibernate.Config\ConfigureNHibernateSagaPersister.cs:line 80
at Ibfx.BackOffice.Services.NewAccounts.NewAccountsEndpoint.Init() in C:\Dev\TFS\Omega\Src\Svcs\NewAccounts\Src\Service\NewAccountsEndpoint.cs:line 67
at NServiceBus.Host.Internal.GenericHost.Start() in c:\Dev\DotNet\NServiceBus\src\host\NServiceBus.Host\Internal\GenericHost.cs:line 56

Everything works fine if I run the host using my own account, but if I run the host as a service with domain credentials or use those same credentials with the RunAs command I get the above exception. What are the permissions I need to configure so the service will work?

Here's my config:

        var configure = NServiceBus.Configure.With()
            .Log4Net<Log4NetLoggerAdapter>(a => { })
            .UnityBuilder(container)
            .XmlSerializer()
            .RijndaelEncryptionService()
            .MsmqTransport()
                .IsTransactional(false)
                .PurgeOnStartup(false)
                .MsmqSubscriptionStorage();

        configure.Configurer.ConfigureComponent<MsmqSubscriptionStorage>(
                    ComponentCallModelEnum.None).ConfigureProperty(p => p.DontUseExternalTransaction
                    , true
                );

        IBus bus = configure.UnicastBus()
            .ImpersonateSender(true)
            .LoadMessageHandlers()
            .Sagas()
            .NHibernateSagaPersister()
        .CreateBus()
        .Start();

And I have a NServiceBus.Host.exe.config file with the following:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的呼吸 2024-10-23 14:07:59

当您暂时给予所有人和匿名登录对指定目录的完全控制权时会发生什么?如果这解决了异常,那么这肯定是一个安全问题。您是否使用 |DataDirectory|在你的连接字符串中?您确定该进程实际上正在查看您认为它正在查看的目录吗?

接下来,我将尝试在内存连接字符串设置中使用 SQLite,看看它是否至少能够创建一个数据库并使用它:

":memory:;Version=3;New=True;Pooling=True;Max Pool Size=1;"

上面的字符串使用内存中的 SQLite,但保持单个连接打开,以便表和数据继续存在,直到进程退出。

我使用的另一个策略是将 saga 持久化器更改为另一种 SQL 风格,例如 MS SQL,看看是否可以解决问题。

What happens when you temporarily give EVERYONE and ANONYMOUS LOGON Full Control over the directory specified? If that solves the exception, it's definitely a security issue. Are you using |DataDirectory| in your connection string? Are you sure the process is actually looking at the directory that you think it's looking at?

Following that, I would try using the SQLite in memory connection string settings to see if it's able to at least create a database and use it:

":memory:;Version=3;New=True;Pooling=True;Max Pool Size=1;"

The above string uses in-memory SQLite but keeps a single connection open so that the tables and data continue to exist until the process exits.

Another strategy that I would use is to change the saga persister to another SQL flavor, such as MS SQL to see if that solves it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文