【问题标题】:How to reference an initialized embedded RavenDB instance in a Class Library?如何在类库中引用已初始化的嵌入式 RavenDB 实例?
【发布时间】:2011-12-17 06:45:38
【问题描述】:

我的情况是这样的:

我有一个在类库 (DLL) 中实现的自定义 RavenDB membership provider。此提供程序需要访问数据库来存储和检索用户和角色信息。我想使用同一个应用数据库来存储会员信息,以避免多一个数据库。

我不知道如何在类库代码中获取对已经初始化的数据库(app数据库)的引用。我想我在这里走错路了...... :)

一些代码:

bool embeddedStore = Convert.ToBoolean(config["enableEmbeddableDocumentStore"]);

if (embeddedStore)
{
    _documentStore = new EmbeddableDocumentStore()
    {
        // Here I'm using the same connection string used by the app.
        // This gives me an error when I try to open a session in the DocumentStore.
        ConnectionStringName =
            config["connectionStringName"]
    };
}
else
{
    _documentStore = new DocumentStore()
    {
        ConnectionStringName =
            config["connectionStringName"]
    };
}

这是 Web.config 中存在的连接字符串:

<add name="RavenDB" connectionString="DataDir = ~\App_Data\Database" />

如何在自定义成员资格提供程序中重复使用相同的数据库?有什么想法吗?

我考虑将类库代码文件移动到 Web 项目中。这样我可以很容易地获得对DocumentStore 的引用,但是代码不会像我想要的那样有条理。

我还尝试使用 2 个 RavenDB 数据库:1 个用于应用程序,1 个用于会员提供程序,但由于我以嵌入式方式运行 RavenDB,我无法使其正常工作。

这些是我迄今为止在尝试过程中遇到的错误:

RavenDB Could not open transactional storage.

Temp path already used by another database instance.

【问题讨论】:

    标签: asp.net-membership ravendb class-library multiple-databases


    【解决方案1】:

    您需要将打开的文档存储的实例传递给您的 dll。 您可以使用容器或通过提供 API 调用来做到这一点。 不能有两个实例使用同一个数据库。

    【讨论】:

    • 天哪……我不想采用集装箱方式,因为它对我的需要来说太多了。在您回答后,灯亮了,我采用了 API 调用方式。我做了这里描述的事情:github.com/csainty/Glimpse.RavenDb/wiki/How-to-use 现在我在初始化 RavenDB 应用程序实例后使用它:RavenDBMembership.Provider.RavenDBMembershipProvider.AttachTo(_documentStore);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多