using SqlSugar;
|
|
namespace AStation.DAL
|
{
|
/// <summary>
|
/// 数据库连接辅助类
|
/// </summary>
|
internal class ConnectionFactory
|
{
|
private static ConnectionConfig _config = null;
|
|
/// <summary>
|
/// 创建连接对象
|
/// </summary>
|
public static ConnectionConfig BuildConnection()
|
{
|
try
|
{
|
var dbName = "Db4Basic.db";
|
var filePath = System.IO.Path.Combine(AStation.DataFolderParas.FullPath, AStation.UserConfig.File.DataSetFolderName, dbName);
|
if (!System.IO.File.Exists(filePath))
|
{
|
throw new System.Exception($"{dbName}文件不存在!Path:{filePath}");
|
}
|
|
_config = new ConnectionConfig()
|
{
|
ConnectionString = $"DataSource={filePath}",
|
IsAutoCloseConnection = true,
|
DbType = SqlSugar.DbType.Sqlite
|
};
|
return _config;
|
}
|
catch (System.Exception ex)
|
{
|
throw ex;
|
}
|
}
|
|
|
|
}
|
}
|