asp.net 多数据库支持的思考
程序员文章站
2024-03-11 12:20:13
一般的多数据库支持在配置文件中如下: 复制代码 代码如下:
一般的多数据库支持在配置文件中如下:
<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,有一些想法。