一般的多數據庫支持在配置文件中如下:
復制代碼 代碼如下:
<connectionStrings>
<add name="MyCmsConnectionString" connectionString="server=(local);user id=sa;pwd=123456;database=mycms;"/>
</connectionStrings>
而數據庫連接如下:
復制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.Common;
namespace COMMON
{
public class Class1
{
public DbConnection GetDatabaseConnection()
{
ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["Conn"];
DbProviderFactory factory = DbProviderFactories.GetFactory(settings.ProviderName);
DbConnection conn = factory.CreateConnection();
conn.ConnectionString = settings.ConnectionString;
return conn;
}
}
}
但接下來呢?研究了discuz和其他一些支持多數據庫的cms,有一些想法。