SQL Server nhibernate configuration not connecting to database

niwlg2el  于 2023-10-15  发布在  其他
关注(0)|答案(1)|浏览(136)

I encountered an issue:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details. )

it seems that I cannot connect to my local database which is configured in my nhibernate.xml . the same connection string is working when using other forms of connection (ADO.net, EntityFrameWork). Am I missing something here?

here is my xml file:

<?xml version='1.0' encoding='utf-8'?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="connection.connection_string">Server=(localdb)\mssqllocaldb;Database=my_database;Trusted_Connection=True;MultipleActiveResultSets=true</property>
        <property name="show_sql">true</property>
        <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    </session-factory>
</hibernate-configuration>

I already tried changing the backslashes to double, removing the localdb, and any other combinations of the connection string.

tktrz96b

tktrz96b1#

I manage to fix this issue. Apparently. nhibernate doesn't accept the usual connection string keywords. What I did is use the Named Pipe. Here's what I did

  1. Open CMD
  2. Run the following command list down all the instances

SqlLocalDB.exe info

  1. Then run the command

SqlLocalDB.exe info MyInstance

  1. Copy the Instance Pipe Name

If Instance pipe name is blank, make sure your server is running and try connecting to your server via SQL.

相关问题