tangxu
2024-04-30 26d8996e55c33186800031f7c305688035bb3182
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
            }
        }
 
 
 
    }
}