3
Answers

Exe file not running in a scheduler

I created the exe file using VS2010- Console Application.Actually the code run sucessfully without any error.
Here my code for your reference:
  1. namespace Automation  
  2. {  
  3.  class Program  
  4.  {  
  5.  static void Main(string[] args)  
  6.  {  
  7.  DateTime currnt = DateTime.Now;  
  8.  Automation.details details = new details();//general usage  
  9. Automation.userdetails userdetails = new userdetails();//Whole details   
  10. tosql data = new tosql();//To store the data to sql  
  11. var dir = AppDomain.CurrentDomain.BaseDirectory; string filepath = Path.Combine(dir, "cmd.exe");//Path for cmd  
  12. string lmutilfolder = "MASTERINPUT";//path for input  
  13. string constrPath = Path.Combine(dir, lmutilfolder);//text file output path  
  14. string[] Connectionstringpath = System.IO.File.ReadAllLines(@"" + constrPath + "\\lmutilstatement.txt");  
  15.   try  
  16.     {  
  17.     Process cmd = new Process();  
  18.      for (int i = 0; i < Connectionstringpath.Length; i++)  
  19.       {  
  20.         string constr = Connectionstringpath[i];  
  21.         string[] split = constr.Split(new char[] { ',' });  
  22.         string name = split[1];  
  23.         string arg = split[0];  
  24.         string date = DateTime.Now.ToString("dd-MM-yyyy HH_mm_ss");  
  25.         cmd.StartInfo.FileName = filepath;  
  26.         cmd.StartInfo.RedirectStandardInput = true;  
  27.         cmd.StartInfo.RedirectStandardOutput = true;  
  28.         cmd.StartInfo.CreateNoWindow = true;  
  29.         cmd.StartInfo.UseShellExecute = false;  
  30.         cmd.Start();  
  31.         cmd.StandardInput.WriteLine(arg);  
  32.         cmd.StandardInput.Flush();  
  33.         cmd.StandardInput.Close();  
  34.         string sRes = cmd.StandardOutput.ReadToEnd();  
  35.     string[] path = System.IO.File.ReadAllLines(@"" + outputPath1 + "\\" + name + " " + date + ".txt");  
  36.             pathpath = path.Where(x => !string.IsNullOrEmpty(x)).DefaultIfEmpty().ToArray();  
  37.    Array.Resize(ref path, path.Length - 1);  
  38.    details.loaddata(path, currnt);  //send detail to a class file
  39.   }  
  40.   data.loadtosql(details.licensedetail);  
  41.   Console.WriteLine("Your output were extracted.......");  
  42.   }  
  43.             catch (Exception e)  
  44.             {  
  45.                   
  46.    string errorfolder = "Error";  
  47.    string eerror = e.Message;  
  48.   string Fname = "error";  
  49.    string Fdate = DateTime.Now.ToString("dd-MM-yyyy HH_mm_ss");  
  50.                string errorfilePath = Path.Combine(dir, errorfolder);//text file output path  
  51.                 string createTextFile1 = "";  
  52.                 string outPath = @"" + errorfilePath + "\\" + Fname + " " + Fdate + ".txt";  
  53.                 createTextFile1 += "" + error + Environment.NewLine;  
  54.                 System.IO.File.WriteAllText(outPath, createTextFile1);  
  55.             }  
  56.              
  57.         }  
  58.     }  
  59.   
  60.     class tosql  
  61.     {  
  62.         storedata store = new storedata();  
  63.         public void loadtosql(DataTable user)  
  64.         {  
  65.             store.BatchBulkCopyuserdetails(user);  
  66.         }  
  67.   
  68.     }  
  69. }  
 When i put this in a scheduler to run every hour.But its creating some error.
Error is :Sequence contains no elements .
 I don't know why this arise.Help me to solve this.
 
Answers (3)