using SqlSugar;
namespace IStation.DAL
{
///
/// 数据库连接辅助类
///
public class ConnectionFactory
{
private static long _projectId;
private static ConnectionConfig _basicConfig = null;
///
/// 创建连接对象
///
public static ConnectionConfig BasicConnection(long projectId)
{
try
{
if (_projectId == projectId)
{
if (_basicConfig != null)
return _basicConfig;
}
_projectId = projectId;
var dbName = SettingsD.File.BasicDB;
var filePath = $"{FileHelper.GetProjectFolder(projectId)}\\{dbName}";
if (!System.IO.File.Exists(filePath))
{
throw new System.Exception($"{dbName}文件不存在!Path:{filePath}");
}
_basicConfig = new ConnectionConfig()
{
ConnectionString = $"DataSource={filePath}",
IsAutoCloseConnection = true,
DbType = SqlSugar.DbType.Sqlite
};
return _basicConfig;
}
catch (System.Exception)
{
// LogHelper.Error(ex.Message);
return null;
}
}
}
}