我的情况是:
我有一个在类库(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.
答案 0 :(得分:1)
您需要将打开的文档存储的实例传递给您的dll。 您可以使用容器或提供API调用来执行此操作。 你不能让两个实例使用相同的数据库。