commit for push and new computer

This commit is contained in:
Paul Trowbridge 2018-11-07 12:56:47 -05:00
parent dadcc2afd8
commit b94e2b4dfb

View File

@ -23,8 +23,13 @@ namespace test
string nr = ""; string nr = "";
string nc = ""; string nc = "";
string nl = Environment.NewLine; string nl = Environment.NewLine;
System.Data.Odbc.OdbcConnection ibmc = new System.Data.Odbc.OdbcConnection(); //declaring these objects globally will asume these libraries exist, they may not
NpgsqlConnection pgc = new NpgsqlConnection(); System.Data.Odbc.OdbcConnection s_odbc = new System.Data.Odbc.OdbcConnection();
System.Data.Odbc.OdbcConnection d_odbc = new System.Data.Odbc.OdbcConnection();
NpgsqlConnection s_npgsql = new NpgsqlConnection();
NpgsqlConnection d_npgsql = new NpgsqlConnection();
System.Data.Common.DbConnection sc; //source connection
System.Data.Common.DbConnection dc; //destination connection
string msg = "Help:"; string msg = "Help:";
msg = msg + nl + "version 0.25"; msg = msg + nl + "version 0.25";
@ -118,22 +123,41 @@ namespace test
//-------------------------------------------establish connections------------------------------------------------- //-------------------------------------------establish connections-------------------------------------------------
//setup source
switch (sdt){
case "odbc":
try { try {
ibmc.ConnectionString = scs; s_odbc.ConnectionString = scs;
} }
catch (Exception e) { catch (Exception e) {
Console.Write(nl + "bad source connection string: " + e.Message); Console.Write(nl + "bad source connection string: " + e.Message);
return; return;
} }
sc = s_odbc;
return;
default:
break;
}
//setup destination
switch (ddt) {
case "npgsql":
try { try {
pgc.ConnectionString = dcs; d_npgsql.ConnectionString = dcs;
} }
catch (Exception e) { catch (Exception e) {
Console.Write(nl + "bad source connection string: " + e.Message); Console.Write(nl + "bad source connection string: " + e.Message);
return; return;
} }
dc = d_npgsql;
return;
default:
break;
}
//polymorph open
try { try {
ibmc.Open(); sc.Open();
} }
catch (Exception e) { catch (Exception e) {
Console.Write(nl + "issue connection to source: " + e.Message); Console.Write(nl + "issue connection to source: " + e.Message);
@ -141,10 +165,10 @@ namespace test
} }
try { try {
pgc.Open(); dc.Open();
} }
catch (Exception e) { catch (Exception e) {
ibmc.Close(); sc.Close();
Console.Write(nl + "issue connecting to destination: "+ e.Message); Console.Write(nl + "issue connecting to destination: "+ e.Message);
} }
@ -152,26 +176,29 @@ namespace test
//----------------------------------------------setup commands--------------------------------------------------- //----------------------------------------------setup commands---------------------------------------------------
var ibmcmd = new System.Data.Odbc.OdbcCommand(sq,ibmc); var s_cmd = new System.Data.Odbc.OdbcCommand();
var pgcom = pgc.CreateCommand(); var pgcom = d_npgsql.CreateCommand();
//---------------------------------------------begin transaction--------------------------------------------------------- //---------------------------------------------begin transaction---------------------------------------------------------
Console.Write(nl); Console.Write(nl);
Console.Write("etl start:" + DateTime.Now.ToString()); Console.Write("etl start:" + DateTime.Now.ToString());
NpgsqlTransaction pgt = pgc.BeginTransaction(); NpgsqlTransaction pgt = pgc.BeginTransaction();
ibmcmd.CommandTimeout = 6000; s_odbcommandTimeout = 6000;
System.Data.Odbc.OdbcDataReader ibmdr; s_odbcommandTimeout = 6000;
system.Data.Odbc.OdbcDataReader ibmdr;
try { try {
ibmdr = ibmcmd.ExecuteReader(); ibmdr = s_odbcxecuteReader();
} ibmdr = s_odbcxecuteReader();
d }
catch (Exception e) { catch (Exception e) {
Console.Write(nl); Console.Write(nl);
Console.Write("error on source sql:"); Console.Write("error on source sql:");
Console.Write(nl); Console.Write(nl);
Console.Write(e.Message); Console.Write(e.Message);
ibmc.Close(); s_odbcse();
pgc.Close(); s_odbcse();
pgc.Cldse();
return; return;
} }
//setup getv object array dimensioned to number of columns for scenario //setup getv object array dimensioned to number of columns for scenario
@ -269,8 +296,9 @@ namespace test
Console.Write(nl); Console.Write(nl);
Console.Write(e.Message); Console.Write(e.Message);
System.IO.File.WriteAllText(@"C:\Users\ptrowbridge\Downloads\runner_error.sql",sql); System.IO.File.WriteAllText(@"C:\Users\ptrowbridge\Downloads\runner_error.sql",sql);
ibmc.Close(); s_odbcse();
pgt.Rollback(); s_odbcse();
pgt.Rollbdck();
pgc.Close(); pgc.Close();
return; return;
} }
@ -288,8 +316,9 @@ namespace test
Console.Write(nl); Console.Write(nl);
Console.Write(e.Message); Console.Write(e.Message);
System.IO.File.WriteAllText(@"C:\Users\ptrowbridge\Downloads\runner_error.sql",sql); System.IO.File.WriteAllText(@"C:\Users\ptrowbridge\Downloads\runner_error.sql",sql);
//ibmc.Close(); //s_odbcse();
pgt.Rollback(); //s_odbcse();
pgt.Rodlback();
pgc.Close(); pgc.Close();
return; return;
} }
@ -298,8 +327,9 @@ namespace test
} }
pgt.Commit(); pgt.Commit();
ibmc.Close(); s_odbcse();
pgc.Close(); s_odbcse();
pgc.Cldse();
Console.Write(nl); Console.Write(nl);
Console.Write("etl end:" + DateTime.Now.ToString()); Console.Write("etl end:" + DateTime.Now.ToString());