如何在 NHibernate 中动态设置连接字符串

发布于 2024-09-02 23:08:09 字数 1398 浏览 2 评论 0原文

我想使用以下代码为 NHibernate 分配连接字符串,但它抛出异常。

log4net.Config.DOMConfigurator.Configure();
Configuration config = new Configuration();
IDictionary props = new Hashtable();

props["hibernate.connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
props["hibernate.dialect"] = "NHibernate.Dialect.MsSql2000Dialect";
props["hibernate.connection.driver_class"] = "NHibernate.Driver.SqlClientDriver";
props["hibernate.connection.connection_string"] = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Sample;Data Source=HYDHTC92318D\SQLEXPRESS";
props["hibernate.connection.current_session_context_class"] = "web";
props["hibernate.connection.show_sql"] = "true";

props["hibernate.connection.proxyfactoryfactory.factory_class"] = "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";

foreach (DictionaryEntry de in props)
{
  config.SetProperty(de.Key.ToString(), de.Value.ToString());
}

config.AddAssembly("nhibernator");
factory = config.BuildSessionFactory();
session = factory.OpenSession();

例外:

未配置 ProxyFactoryFactory。 使用可用的 NHibernate.ByteCode 提供程序之一初始化会话工厂配置部分的“proxyfactory.factory_class”属性。 例子: NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu 例子: NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle**

请让我知道解决方案。

I want assign connection string for NHibernate using following code but it throw an exception.

log4net.Config.DOMConfigurator.Configure();
Configuration config = new Configuration();
IDictionary props = new Hashtable();

props["hibernate.connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
props["hibernate.dialect"] = "NHibernate.Dialect.MsSql2000Dialect";
props["hibernate.connection.driver_class"] = "NHibernate.Driver.SqlClientDriver";
props["hibernate.connection.connection_string"] = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Sample;Data Source=HYDHTC92318D\SQLEXPRESS";
props["hibernate.connection.current_session_context_class"] = "web";
props["hibernate.connection.show_sql"] = "true";

props["hibernate.connection.proxyfactoryfactory.factory_class"] = "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";

foreach (DictionaryEntry de in props)
{
  config.SetProperty(de.Key.ToString(), de.Value.ToString());
}

config.AddAssembly("nhibernator");
factory = config.BuildSessionFactory();
session = factory.OpenSession();

Exception:

The ProxyFactoryFactory was not configured.
Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.
Example:
NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
Example:
NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle**

Please let me know the solution.

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

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

发布评论

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

评论(1

骑趴 2024-09-09 23:08:09

请参阅此处的解决方案:

如何加载应用程序设置到 NHibernate.Cfg.Configuration 对象?

我还没有测试过这一点,但您可能想尝试更改:

props["hibernate.connection.proxyfactoryfactory.factory_class"] =
  "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";

为:

props["proxyfactory.factory_class"] =
  "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";

proxyfactory 不是连接的一部分。

See here for a solution:

How to load application settings to NHibernate.Cfg.Configuration object?

I haven't tested this, but you may want to try changing:

props["hibernate.connection.proxyfactoryfactory.factory_class"] =
  "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";

to:

props["proxyfactory.factory_class"] =
  "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";

The proxyfactory isn't part of the connection.

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