1
嗨朋友我有一個控制檯應用程序,它從Access數據庫更新三個表中讀取數據,我使用名爲automate 9.0的軟件自動執行此操作我需要知道如果exe失敗,爲什麼失敗,所以我跟蹤一些枚舉值,我認爲這是我的主要方法導致錯誤。不包含適用於入口點的靜態主要方法(但我已將它配置正確)
namespace accessmovingtest
{
enum ExitCode : int
{
Success = 0,
SqlError = 1,
CannotFindFileAccessDB = 2,
ConnectionRelatedError = 3
}
class Program
{
public static ExitCode Main(string[] args)
{
ExitCode RetVal;
string accdbConnStr = ConfigurationManager.ConnectionStrings["AccessDBtoSql.Properties.Settings.Company_Master_DataConnectionString"].ToString();
var con = new OdbcConnection(accdbConnStr);
try
{
con.Open();
con.Close();
}
catch(Exception ex)
{
Console.Out.WriteLine(ex.StackTrace);
Console.Out.WriteLine(ex.Message);
Console.Out.WriteLine(ex.TargetSite);
Console.WriteLine("Cannot Establish a connection to the access database");
RetVal = ExitCode.ConnectionRelatedError;
return RetVal;
}
try
{
string accdbConnStrr = ConfigurationManager.ConnectionStrings["AccessDBtoSql.Properties.Settings.Company_Master_DataConnectionString"].ToString();
if (!File.Exists(accdbConnStrr))
{
Console.WriteLine("AccessDb Found");
}
}
catch (FileNotFoundException ex)
{
Console.Out.WriteLine(ex.StackTrace);
Console.Out.WriteLine(ex.Message);
Console.WriteLine("Cannot Find Access Data");
RetVal = ExitCode.CannotFindFileAccessDB;
return RetVal;
}
catch (Exception ex)
{
Console.Out.WriteLine(ex.Message);
}
try
{
accesstosqlitemmaster();
}
catch (Exception ex)
{
Console.Out.WriteLine(ex.StackTrace);
Console.Out.WriteLine(ex.Message);
RetVal = ExitCode.SqlError;
return RetVal;
}
try
{
accesstosqlpiecedimensionmasterdata();
}
catch (Exception ex)
{
Console.Out.WriteLine(ex.StackTrace);
Console.Out.WriteLine(ex.Message);
RetVal = ExitCode.SqlError;
return RetVal;
}
try
{
accesstosqlitemdeslookups();
}
catch (Exception ex)
{
Console.Out.WriteLine(ex.StackTrace);
Console.Out.WriteLine(ex.Message);
RetVal = ExitCode.SqlError;
return RetVal;
}
RetVal = ExitCode.Success;
return RetVal;
}
獲取錯誤上的ExitCode旁邊的主要方法