简体   繁体   中英

NHibernate: Instance failure during BuildSessionFactory

I'm trying NHibernate and at the beginning I get:

System.InvalidOperationException: Instance failure.

at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover, Boolean isFirstTransparentAttempt, SqlAuthenticationMethod authType)
... at System.Data.SqlClient.SqlConnection.Open()
at NHibernate.Connection.DriverConnectionProvider.GetConnection()
... at NHibernate.Cfg.Configuration.BuildSessionFactory()
at NHibernateDemo.Program.Main(String[] args)

The configuration is:

<hibernate-configuration xmlns = "urn:nhibernate-configuration-2.2">
<session-factory>
  <property name = "connection.connection_string">
    Data Source=localhost\\SQLEXPRESS;Initial Catalog=NHibernateDemoDB;Integrated Security=SSPI
  </property>

  <property name = "connection.driver_class">
    NHibernate.Driver.SqlClientDriver
  </property>

  <property name = "dialect">
    NHibernate.Dialect.MsSql2012Dialect
  </property>

  <mapping assembly = "NHibernateDemo"/>
</session-factory>
</hibernate-configuration>

The code is:

    static void Main(string[] args)
    {
        var cfg = new NHibernate.Cfg.Configuration();
        cfg.Configure();

        var sessionFactory = cfg.BuildSessionFactory();

        Console.ReadLine();
    }

How can I solve it?

Maybe there is a problem in SQL Server?

The problem is the double quotes in the connection string: change it to this.

Data Source=localhost\SQLEXPRESS; …

Ref: Fixing "Instance Failure" when connecting to Sql Server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM