Problem connecting to MySQL from NHibernate
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-configura开发者_高级运维tion>
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.
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>
精彩评论