You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.1 KiB
C#
63 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using HuizhongLibrary.Common.Configuration;
|
|
|
|
namespace HuizhongLibrary.Data
|
|
{
|
|
public static class DatabaseFactory
|
|
{
|
|
public static Database CreateDatabase()
|
|
{
|
|
return CreateDatabase("ConnectionString");
|
|
}
|
|
|
|
|
|
public static Database CreateDatabasel()
|
|
{
|
|
return CreateDatabase("BaseConnectionString");
|
|
}
|
|
|
|
|
|
|
|
public static Database CreateDatabase(string name)
|
|
{
|
|
Database db = null;
|
|
if (DataCache.ConfigCache.ContainsKey(name) == false)
|
|
{
|
|
ConfigurationSourceSection.GetConnection(name);
|
|
}
|
|
if (DataCache.ConfigCache.ContainsKey(name) == false) return null;
|
|
string Namespace = DataCache.ConfigCache[name].Namespace;
|
|
string ConnectionString = DataCache.ConfigCache[name].Value;
|
|
if (string.IsNullOrEmpty(ConnectionString) == true) return null;
|
|
if (Namespace == "System.Data.Oledb")
|
|
{
|
|
ConnectionString = CustomIO.AccessReplacePath(ConnectionString);
|
|
}
|
|
db = new Database(Namespace, ConnectionString);
|
|
return db;
|
|
}
|
|
|
|
public static Database CreateDatabase2(string name)
|
|
{
|
|
Database db = null;
|
|
if (DataCache.ConfigCache.ContainsKey(name) == false)
|
|
{
|
|
ConfigurationSourceSection.GetConnection2(name);
|
|
}
|
|
if (DataCache.ConfigCache.ContainsKey(name) == false) return null;
|
|
string Namespace = DataCache.ConfigCache[name].Namespace;
|
|
string ConnectionString = DataCache.ConfigCache[name].Value;
|
|
if (string.IsNullOrEmpty(ConnectionString) == true) return null;
|
|
if (Namespace == "System.Data.Oledb")
|
|
{
|
|
ConnectionString = CustomIO.AccessReplacePath(ConnectionString);
|
|
}
|
|
db = new Database(Namespace, ConnectionString);
|
|
return db;
|
|
}
|
|
}
|
|
} |