使用工厂方法模式实现多数据库WinForm手机号码查询器
2010-04-08 00:00:00 来源:WEB开发网SqlConnStr.cs文件用于获得相应的连接字符串ConnectionString
/// <summary>
/// 获得连接字符串ConnectingString
/// </summary>
public static class SqlConnString
{
public static string ReturnConnString()
{
string _appPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//当前程序路径
string _dal = System.Configuration.ConfigurationManager.AppSettings["DAL"];//获取App.Config中DAL
string _conn = "";
switch (_dal)
{
/*Sqlite数据库*/
case "CuteMobileSearch.SQLiteDAL":
default:
_appPath = "Data Source=" + _appPath;
_appPath += System.Configuration.ConfigurationManager.AppSettings["SqliteFile"];
return _appPath;
/*SqlServer数据库*/
case "CuteMobileSearch.SQLServerDAL":
_conn = "server=.;database=CuteMobileDB;uid=sa;pwd=123456";
return _conn;
/*access数据库*/
case "CuteMobileSearch.OleDAL":
_appPath = "provider=microsoft.jet.oledb.4.0;data source=" + _appPath + System.Configuration.ConfigurationManager.AppSettings["OleFile"];
return _appPath;
}
}
}
更多精彩
赞助商链接