This project is read-only.

数据库连接配置

  在解决方案的每个项目中添加对NLite的引用:在工具中找到程序包管理器,选择程序包管理器控制台。在程序包管理器控制台中输入install-package nlite -project nlite.data.test(项目名称)

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的值是一样的。)

后台调用连接字符串时输入连接字符串的名称Northwind

 

       protected Northwind db;

        protected virtual string ConnectionStringName
        {
            get { return "Northwind"; }
        }

        [TestInitialize]
        public void Initialize()
        {
            db = new Northwind(ConnectionStringName);
        }

 

 

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 Nov 6, 2012 at 2:42 AM by g_jia, version 16

Comments

No comments yet.