open call error handling
This commit is contained in:
parent
fd27030a44
commit
a58279e491
53
runner.cs
53
runner.cs
@ -23,7 +23,7 @@ namespace test
|
|||||||
string nl = Environment.NewLine;
|
string nl = Environment.NewLine;
|
||||||
|
|
||||||
string msg = "Help:";
|
string msg = "Help:";
|
||||||
msg = msg + nl + "version 0.20";
|
msg = msg + nl + "version 0.22";
|
||||||
msg = msg + nl + "-scs source connection string";
|
msg = msg + nl + "-scs source connection string";
|
||||||
msg = msg + nl + "-dcs destination connection string";
|
msg = msg + nl + "-dcs destination connection string";
|
||||||
msg = msg + nl + "-sq path to source query";
|
msg = msg + nl + "-sq path to source query";
|
||||||
@ -46,7 +46,13 @@ namespace test
|
|||||||
break;
|
break;
|
||||||
//source query path
|
//source query path
|
||||||
case "-sq":
|
case "-sq":
|
||||||
sq = System.IO.File.ReadAllText(args[i+1]);
|
try {
|
||||||
|
sq = System.IO.File.ReadAllText(args[i+1]);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
Console.Write(nl + "error reasing source sql file: " + e.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
//destination table name
|
//destination table name
|
||||||
case "-dt":
|
case "-dt":
|
||||||
@ -56,19 +62,19 @@ namespace test
|
|||||||
trim = true;
|
trim = true;
|
||||||
break;
|
break;
|
||||||
case "--help":
|
case "--help":
|
||||||
Console.Write(Environment.NewLine);
|
Console.Write(nl);
|
||||||
Console.Write(msg);
|
Console.Write(msg);
|
||||||
return;
|
return;
|
||||||
case "-help":
|
case "-help":
|
||||||
Console.Write(Environment.NewLine);
|
Console.Write(nl);
|
||||||
Console.Write(msg);
|
Console.Write(msg);
|
||||||
return;
|
return;
|
||||||
case "-h":
|
case "-h":
|
||||||
Console.Write(Environment.NewLine);
|
Console.Write(nl);
|
||||||
Console.Write(msg);
|
Console.Write(msg);
|
||||||
return;
|
return;
|
||||||
case @"\?":
|
case @"\?":
|
||||||
Console.Write(Environment.NewLine);
|
Console.Write(nl);
|
||||||
Console.Write(msg);
|
Console.Write(msg);
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
@ -76,13 +82,13 @@ namespace test
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.Write(Environment.NewLine);
|
Console.Write(nl);
|
||||||
Console.Write(scs);
|
Console.Write(scs);
|
||||||
Console.Write(Environment.NewLine);
|
Console.Write(nl);
|
||||||
Console.Write(dcs);
|
Console.Write(dcs);
|
||||||
Console.Write(Environment.NewLine);
|
Console.Write(nl);
|
||||||
Console.Write(sq);
|
Console.Write(sq);
|
||||||
Console.Write(Environment.NewLine);
|
Console.Write(nl);
|
||||||
Console.Write(dt);
|
Console.Write(dt);
|
||||||
|
|
||||||
//return;
|
//return;
|
||||||
@ -91,8 +97,23 @@ namespace test
|
|||||||
|
|
||||||
var ibmc = new System.Data.Odbc.OdbcConnection(scs);
|
var ibmc = new System.Data.Odbc.OdbcConnection(scs);
|
||||||
var pgc = new NpgsqlConnection(dcs);
|
var pgc = new NpgsqlConnection(dcs);
|
||||||
|
try {
|
||||||
ibmc.Open();
|
ibmc.Open();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
Console.Write(nl + "issue connection to source: " + e.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
pgc.Open();
|
pgc.Open();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
ibmc.Close();
|
||||||
|
Console.Write(nl + "issue connecting to destination: "+ e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------setup commands---------------------------------------------------
|
//----------------------------------------------setup commands---------------------------------------------------
|
||||||
|
|
||||||
@ -101,7 +122,7 @@ namespace test
|
|||||||
|
|
||||||
//---------------------------------------------begin transaction---------------------------------------------------------
|
//---------------------------------------------begin transaction---------------------------------------------------------
|
||||||
|
|
||||||
Console.Write(Environment.NewLine);
|
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;
|
ibmcmd.CommandTimeout = 6000;
|
||||||
@ -110,9 +131,9 @@ namespace test
|
|||||||
ibmdr = ibmcmd.ExecuteReader();
|
ibmdr = ibmcmd.ExecuteReader();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Console.Write(Environment.NewLine);
|
Console.Write(nl);
|
||||||
Console.Write("error on source sql:");
|
Console.Write("error on source sql:");
|
||||||
Console.Write(Environment.NewLine);
|
Console.Write(nl);
|
||||||
Console.Write(e.Message);
|
Console.Write(e.Message);
|
||||||
ibmc.Close();
|
ibmc.Close();
|
||||||
pgc.Close();
|
pgc.Close();
|
||||||
@ -210,7 +231,7 @@ namespace test
|
|||||||
pgcom.ExecuteNonQuery();
|
pgcom.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Console.Write(Environment.NewLine);
|
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();
|
ibmc.Close();
|
||||||
@ -229,7 +250,7 @@ namespace test
|
|||||||
pgcom.ExecuteNonQuery();
|
pgcom.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Console.Write(Environment.NewLine);
|
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();
|
//ibmc.Close();
|
||||||
@ -245,7 +266,7 @@ namespace test
|
|||||||
ibmc.Close();
|
ibmc.Close();
|
||||||
pgc.Close();
|
pgc.Close();
|
||||||
|
|
||||||
Console.Write(Environment.NewLine);
|
Console.Write(nl);
|
||||||
Console.Write("etl end:" + DateTime.Now.ToString());
|
Console.Write("etl end:" + DateTime.Now.ToString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user