找不到命名连接字符串服务器 nhibernate MySql

本文关键字:服务器 nhibernate MySql 字符串 连接 找不到 | 更新日期: 2023-09-27 18:30:58

编程新手并收到此错误。我不知道请帮忙。这是我的保存按钮单击和我的配置文件。

  private void save_Click(object sender, EventArgs e)
        {
            Details d =new Details();
            d.Firstname = firstname.Text;
            Configuration cfg=new Configuration();
            cfg.Configure("NHibernate.xml");
            ISessionFactory sessionfactory = cfg.BuildSessionFactory();
            ISession session = sessionfactory.OpenSession();
            ITransaction tx = session.BeginTransaction();
            session.Save(d);
            tx.Commit();
  }

我的配置文件处于休眠状态.xml

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="hibernate-configuration"
             type="NHibernate.Cfg.ConfigurationSectionHandler,NHibernate"/>
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">
      NHibernate.Connection.DriverConnectionProvider
    </property>
    <property name="dialect">
      NHibernate.Dialect.MySQLDialect,Nhibernate
    </property>
    <property name="connection.connection_string_name">
      Server=localhost;Database=mohit;User ID=root;Password=root
    </property>
    <mapping assembly="TestNhibernate"/>
  </session-factory>
  </hibernate-configuration>
</configuration>
please help

找不到命名连接字符串服务器 nhibernate MySql

您可以使用

以下name="connection.connection_string"

<session-factory>
    ...
    <property name="connection.connection_string"> 
      Server=localhost;Database=mohit;User ID=root;Password=root
    </property>

或者具有<connectionStrings>配置的name="connection.connection_string_name"

// another web.config section "<connectionStrings>"
<connectionStrings>
  <add name="MyName" 
    connectionString="Server=localhost;Database=mohit;User ID=root;Password=root" />
</connectionStrings>
// here we reference the name defined in the other section
<session-factory>
    ...
    <property name="connection.connection_string_name">MyName</property>