Problem connecting to MySQL from NHibernate

為{幸葍}努か 提交于 2019-12-25 03:13:47

问题


I am using NHibernate 3.0 with MySQL as the database. On my localhost, I can connect to the database and do everything I want to. However, whenever I upload the files to the production server, I get an error which states:

"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: 26 - Error Locating Server/Instance Specified)"

The web.config file has the following section:

<hibernate-configuration xmlns="urn:nhibernate-configuration">    
<session-factory >
  <property name="connection.provider" specificversion="false">NHibernate.Connection.DriverConnectionProvider</property>
  <property name="connection.driver_class" specificversion="false">NHibernate.Driver.MySqlDataDriver</property>
 <!--<property name="connection.connection_string" specificversion="false">
    Data Source=localhost;Port=3306;Database=sampledb;Uid=myuser;Pwd=mypass
    DSN=mydsn;UID=myuser;PWD==mypass
  </property>-->
  <property name="connection.connection_string">
    Server=localhost;Database=sampledb;User ID=myuser;Password=mypass;
  </property>
  <property name="proxyfactory.factory_class" specificversion="false">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>      
  <property name="dialect" specificversion="false">NHibernate.Dialect.MySQLDialect</property>      
  <property name="hbm2ddl.keywords" specificversion="false">none</property>
  <mapping assembly="App_Code.NHibernateHelpers" />
</session-factory>
</hibernate-configuration>

I have even tried the connection strings in the commented section shown above but nothing seems to work...yet all those work on my local machine. Can someone please tell me what I may be missing? My production server is a Windows 2003 server running .NET 2.x and MySQL connector 5.0.9.

Thanks.


回答1:


Double check that the correct web.config is used. SQL Server as mentioned in you error is MS SqlServer and not mysql.

Have you forgot to add this to your web.config?

<configSections>
  <section name="hibernate-configuration"
  type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>


来源:https://stackoverflow.com/questions/5067126/problem-connecting-to-mysql-from-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!