/// <summary> /// 初始化要使用的 Wunion.DataAdapter.NetCore 数据引擎。 /// </summary> /// <param name="env">用于获到当前请求 Hotting 信息的对象。</param> /// <param name="configuration">用于读取 appsettings.json 配置文件的对象。</param> public static void UseDataEngine(IHostingEnvironment env, IConfiguration configuration) { IConfigurationSection Section = configuration.GetSection("ConnectionStrings"); SqliteDbAccess SqliteDBA = new SqliteDbAccess(); string wwwroot = env.WebRootPath; if (wwwroot[wwwroot.Length - 1] != '\\') { wwwroot += "\\"; } SqliteDBA.ConnectionString = Section.GetValue <string>("SQLite").Replace("{wwwroot}", wwwroot); DataEngine.AppendDataEngine(SqliteDBA, new SqliteParserAdapter()); // 添加为默认引擎。 SqlServerDbAccess MsSqlDBA = new SqlServerDbAccess(); MsSqlDBA.ConnectionString = Section.GetValue <string>("SQLServer"); DataEngine.AppendDataEngine(MsSqlDBA, new SqlServerParserAdapter(), "SQLServer"); MySqlDBAccess MySqlDBA = new MySqlDBAccess(); MySqlDBA.ConnectionString = Section.GetValue <string>("MariaDB"); DataEngine.AppendDataEngine(MySqlDBA, new MySqlParserAdapter(), "MariaDB"); NpgsqlDbAccess NpgsqlDBA = new NpgsqlDbAccess(); NpgsqlDBA.ConnectionString = Section.GetValue <string>("PostgreSQL"); DataEngine.AppendDataEngine(NpgsqlDBA, new NpgsqlParserAdapter(), "PostgreSQL"); }
protected DataEngine GetDbContext(string dbtype, bool useConnectionPool = true) { DbAccess dba = null; ParserAdapter adapter = null; switch (dbtype?.ToLower()) { case "ms-sql": dba = new SqlServerDbAccess(); dba.ConnectionString = "Server=(local);Database=Wunion.DataAdapter.NetCore.Demo;User ID=sa;Password=ms-sql@(*~-^*);"; adapter = new SqlServerParserAdapter(); break; case "mysql": dba = new MySqlDBAccess(); dba.ConnectionString = "Data Source=192.168.1.106;Database=ksdatab;User ID=cnzhnet;Password=mysql@(*~-^*);"; adapter = new MySqlParserAdapter(); break; case "npgsql": dba = new NpgsqlDbAccess(); dba.ConnectionString = "Host=192.168.1.106;Username=postgres;Password=npgsql@(*~-^*);Database=Wunion.DataAdapter.NetCore.Demo;"; adapter = new NpgsqlParserAdapter(); break; case "sqlite3": dba = new SqliteDbAccess(); dba.ConnectionString = @"Data Source=E:\SQLiteStudio\wdak.sqlite3;"; adapter = new SqliteParserAdapter(); break; } if (dba == null || adapter == null) { return(null); } DataEngine db = new DataEngine(dba, adapter); if (useConnectionPool) { UseConnectionPool(db); } return(db); }