数据库连接配置

 在程序包管理器控制台中输入install-package nlite.data

1.mysql数据库连接配置

   在项目中添加mysql数据库的mysql.dll引用。在App.config中添加连接数据库的配置 

<connectionStrings>
    <clear/> 
        <add providerName="MySql.Data.MySqlClient" name="Northwind" connectionString="Host=localhost;UserName=root;Password=root;Database=nlitedb;Port=3306;CharSet=utf8;Allow Zero Datetime=true" />
</connectionStrings>
<system.data>
    <DbProviderFactories>
      <clear/>
      <add name="MySql Data Provider"
           invariant="MySql.Data.MySqlClient"
           description="ddd"
           type="MySql.Data.MySqlClient.MySqlClientFactory,MySql.Data"/>
    </DbProviderFactories>
</system.data>

(注意:providerNamed的值和invariant的值是一样的。)

2.sqlserver数据库连接配置

在App.config中添加连接sqlserver数据库的配置

<connectionStrings>
    <clear/>
    <add providerName="System.Data.SqlClient" name="Northwind" connectionString="server=localhost;database=test;uid=sa;pwd=123;"/>
</connectionStrings>

3.Access数据库连接配置

在App.config中添加连接Access数据库的配置

<connectionStrings>
    <clear/>
        <add providerName ="System.Data.OleDb" name="Northwind" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=~/../DataBaseAccess/Northwind.mdb;Persist Security Info=True"/>
</connectionStrings>

将access数据库文件放在项目文件夹DataBaseAccess中

4.Sqlite数据库连接配置

在项目中添加Sqlite的引用System.Data.SQLite.dll,在App.config中添加连接Sqlite数据库的配置

<connectionStrings>
    <clear/>
        <add providerName="System.Data.SQLite" name="Northwind" connectionString="Data Source=DataBase/Northwind.sl3;Pooling=true;FailIfMissing=false" />
</connectionStrings>
<system.data>
    <DbProviderFactories>
      <clear/>
      <add name="SQLite Data Provider"
           invariant="System.Data.SQLite"
           description="ddd"
           type="System.Data.SQLite.SQLiteFactory,System.Data.SQLite"/>
    </DbProviderFactories>
</system.data>

(注意:providerNamed的值和invariant的值是一样的.)

5.SqlserverCe数据库连接配置

   在App.config中添加连接SqlserverCe数据库的配置

<connectionStrings> <add providerName="System.Data.SqlServerCe.3.5" name="Northwind" connectionString="Data Source=DataBase/Northwind.sdf;Persist Security Info=True" /> </connectionStrings> 

将SqlserverCe数据库文件放在项目文件夹DataBase中

6.Orcal数据库连接配置

在项目中添加Orcal的引用System.Data.OracleClient。在App.config中添加连接Orcal的数据库配置

<connectionStrings>
       <add providerName ="System.Data.OracleClient" name="Northwind" connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl))); User Id=system;Password=123;"/>
</connectionStrings>
<system.data>
    <DbProviderFactories>
      <clear/>
      <add name="System.Data.OracleClient"
           invariant="System.Data.OracleClient"
           description="ddd"  type="System.Data.OracleClient.OracleClientFactory,System.Data.OracleClient"/>
    </DbProviderFactories>
</system.data>
(注意:providerNamed的值和invariant的值是一样的.)

Last edited Dec 3, 2012 at 7:24 AM by qswang, version 6

Comments

No comments yet.