private void ValidateDbConnection(DbConnectionInfo dbInfo) { try { using (AppHost.GetDbConnectionFactory(dbInfo).OpenDbConnection()) { // sweet! } } catch (Exception ex) { throw new ArgumentException(ex.Message); } }
public static OrmLiteConnectionFactory GetDbConnectionFactory(DbConnectionInfo db) { if (string.IsNullOrWhiteSpace(db.Dialect) || string.IsNullOrWhiteSpace(db.ConnectionString)) { return(null); } IOrmLiteDialectProvider dialectProvider = null; var dialect = db.Dialect.ToLowerInvariant(); var connectionString = db.ConnectionString; if (dialect.Contains("sqlite")) { dialectProvider = SqliteDialect.Provider; } else if (dialect.Contains("pgsql") || dialect.Contains("postgres")) { dialectProvider = PostgreSqlDialect.Provider; } else if (dialect.Contains("mysql")) { dialectProvider = MySqlDialect.Provider; } else if (dialect.Contains("sqlserver")) { if (dialect.Contains("2017")) { dialectProvider = SqlServer2017Dialect.Provider; } else if (dialect.Contains("2016")) { dialectProvider = SqlServer2016Dialect.Provider; } else if (dialect.Contains("2014")) { dialectProvider = SqlServer2014Dialect.Provider; } else if (dialect.Contains("2012")) { dialectProvider = SqlServer2012Dialect.Provider; } else { dialectProvider = SqlServerDialect.Provider; } } return((dialectProvider != null) ? new OrmLiteConnectionFactory(connectionString, dialectProvider): (OrmLiteConnectionFactory)null); }
private static void PersistDbConfig(DbConnectionInfo dbConfig) { var dbConfigFile = GetDbConfigFilePath(); lock (FileLock) { int i = 0; // try up to 10 times while (i <= 10) { try { File.WriteAllText(dbConfigFile, dbConfig.ToJson()); break; } catch { i++; } } } }