1

Hi friends i have a console application that reads data from access database update three tables and i have this automated using an software called automate 9.0 so i need to know if the exe fails and why it fails so i am tracking that with some enum values and i think that is causing errors on my Main Method.

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;


        }

Getting the error on the ExitCode next to the Main Method

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
ExpertWannaBe
  • 117
  • 3
  • 17

1 Answers1

2

According to the C# 5.0 Language Specification, ยง3.1,

Application startup occurs when the execution environment calls a designated method, which is referred to as the application's entry point. This entry point method is always named Main, and can have one of the following signatures:

static void Main() {...}

static void Main(string[] args) {...}

static int Main() {...}

static int Main(string[] args) {...}

You are returning an enum for your main method, not the int underlying the enum which would satisfy the spec.

public static int Main(string[] args) 
{
    ExitCode RetVal;
    ...
    ...
    RetVal = ExitCode.Success;
    return (int)RetVal;
David L
  • 32,885
  • 8
  • 62
  • 93