private void ExecutarPreScripts() { using (var conn = new NpgsqlConnection(_postgresRunner.GetConnectionString())) { conn.Open(); using (var cmd = new NpgsqlCommand("CREATE USER postgres;", conn)) { try { cmd.ExecuteNonQuery(); } catch (Exception) { //throw new Exception($"Erro ao executar o script {file.FullName}. Erro: {ex.Message}"); } } } }
private void MontaBaseDados(PostgresRunner runner) { ExecutarPreScripts(); var scripts = ObterScripts(); using (var conn = new NpgsqlConnection(runner.GetConnectionString())) { conn.Open(); DirectoryInfo d = new DirectoryInfo(scripts); var files = d.GetFiles("*.sql").OrderBy(a => int.Parse(CleanStringOfNonDigits_V1(a.Name))); foreach (var file in files) { string script = File.ReadAllText(file.FullName); byte[] b = File.ReadAllBytes(file.FullName); Encoding enc = null; var textoComEncodeCerto = ReadFileAndGetEncoding(b, ref enc); using (var cmd = new NpgsqlCommand(textoComEncodeCerto, conn)) { try { cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception($"Erro ao executar o script {file.FullName}. Erro: {ex.Message}"); } } } } }
private void MontaBaseDados(PostgresRunner runner) { var scripts = ObterScripts(); using (var conn = new NpgsqlConnection(runner.GetConnectionString())) { conn.Open(); DirectoryInfo d = new DirectoryInfo(scripts); var files = d.GetFiles("*.sql").OrderBy(a => int.Parse(CleanStringOfNonDigits_V1(a.Name))); foreach (var file in files) { string script = File.ReadAllText(file.FullName); using (var cmd = new NpgsqlCommand(script, conn)) { cmd.ExecuteNonQuery(); } } } }