1. 程式人生 > >NHibernate學習之二——.cfg.xml配置大全(資料庫連線配置)

NHibernate學習之二——.cfg.xml配置大全(資料庫連線配置)

一、sql2000/2005.cfg.xml

<?xml version="1.0" ?>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >

<session-factory>

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>

<property name="dialect">NHibernate.Dialect.MsSql2000Dialect/MsSql2005Dialect</property>

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

<property name="connection.connection_string">Server=.;Initial Catalog=dbname;User Id=sa;Password=*****</property>

</session-factory>

</hibernate-configuration>

*************************************************************************************************************************************

二、Mysql.cfg.xml

<?xml version="1.0" encoding="utf-8"?>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >

<session-factory name="NHibernate.Test">

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>

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

<property name="connection.connection_string">

Database=test;Data Source=.;User Id=blah;Password=blah

</property>

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

</session-factory>

</hibernate-configuration>

*************************************************************************************************************************************

三、Access.cfg.xml

<?xml version="1.0" ?>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >

<session-factory>

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>

<property name="dialect">NHibernate.JetDriver.JetDialect, NHibernate.JetDriver</property>

<property name="connection.driver_class">NHibernate.JetDriver.JetDriver, NHibernate.JetDriver</property>

<property name="connection.connection_string">Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FileName.mdb</property>

</session-factory>

</hibernate-configuration>

*************************************************************************************************************************************

4、Oracle.cfg.xml

<?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.OracleDataClientDriver</property>

<property name="connection.connection_string">User ID=id;Password=pw;Data Source=requ;Pooling=true;Connection Lifetime=180;Connection Timeout=30;Min Pool Size=2;Max Pool Size=10;Incr Pool Size=2;</property>

<property name="dialect">NHibernate.Dialect.Oracle10gDialect/Oracle9iDialect </property>

<property name="show_sql">true</property>

</session-factory>

</hibernate-configuration>

*************************************************************************************************************************************

5、Firebird.cfg.xml

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >

<session-factory name="NHibernate.Test">

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>

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

<property name="connection.isolation">ReadCommitted</property>

<property name="connection.connection_string">

Server=localhost;

Database=C:\nhibernate.fdb;

User=SYSDBA;Password=masterkey

</property>

<property name="show_sql">false</property>

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

<property name="use_outer_join">true</property>

<property name="command_timeout">444</property>

<property name="query.substitutions">true 1, false 0, yes 1, no 0</property>

</session-factory>

</hibernate-configuration>

*************************************************************************************************************************************

6、Postgrel.cfg.xml

<?xml version="1.0" encoding="utf-8"?>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >

<session-factory name="NHibernate.Test">

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>

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

<property name="connection.connection_string">

Server=localhost;initial catalog=nhibernate;User ID=nhibernate;Password=********;

</property>

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

</session-factory>

</hibernate-configuration>

*************************************************************************************************************************************

7、DB2.cfg.xml

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0" >

<session-factory name="session">

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>

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

<property name="connection.connection_string">driver={IBM DB2 ODBC DRIVER};Database=db;hostname=host;port=port;protocol=TCPIP; uid=uid; pwd=pwd</property>

<property name="show_sql">true</property>

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

<property name="use_outer_join">true</property>

<mapping resource="..." />

</session-factory>

</hibernate-configuration>

*************************************************************************************************************************************

8、SQLite.cfg.xml

<?xml version="1.0" encoding="utf-8"?>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >

<session-factory name="NHibernate.Test">

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>

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

<property name="connection.connection_string">

Data Source=nhibernate.db;Version=3

</property>

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

<property name="query.substitutions">true=1;false=0</property>

</session-factory>

</hibernate-configuration>