asp.net 中多数据库支持的思考 代码参考示例
来源:不详 责任编辑:栏目编辑 发表时间:2013-07-02 00:44 点击:次
一般的多数据库支持在配置文件中如下:
<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,有一些想法。
代码如下:
<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,有一些想法。
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>