I created the exe file using VS2010- Console Application.Actually the code run sucessfully without any error.
Here my code for your reference:
- namespace Automation
- {
- class Program
- {
- static void Main(string[] args)
- {
- DateTime currnt = DateTime.Now;
- Automation.details details = new details();//general usage
- Automation.userdetails userdetails = new userdetails();//Whole details
- tosql data = new tosql();//To store the data to sql
- var dir = AppDomain.CurrentDomain.BaseDirectory; string filepath = Path.Combine(dir, "cmd.exe");//Path for cmd
- string lmutilfolder = "MASTERINPUT";//path for input
- string constrPath = Path.Combine(dir, lmutilfolder);//text file output path
- string[] Connectionstringpath = System.IO.File.ReadAllLines(@"" + constrPath + "\\lmutilstatement.txt");
- try
- {
- Process cmd = new Process();
- for (int i = 0; i < Connectionstringpath.Length; i++)
- {
- string constr = Connectionstringpath[i];
- string[] split = constr.Split(new char[] { ',' });
- string name = split[1];
- string arg = split[0];
- string date = DateTime.Now.ToString("dd-MM-yyyy HH_mm_ss");
- cmd.StartInfo.FileName = filepath;
- cmd.StartInfo.RedirectStandardInput = true;
- cmd.StartInfo.RedirectStandardOutput = true;
- cmd.StartInfo.CreateNoWindow = true;
- cmd.StartInfo.UseShellExecute = false;
- cmd.Start();
- cmd.StandardInput.WriteLine(arg);
- cmd.StandardInput.Flush();
- cmd.StandardInput.Close();
- string sRes = cmd.StandardOutput.ReadToEnd();
- string[] path = System.IO.File.ReadAllLines(@"" + outputPath1 + "\\" + name + " " + date + ".txt");
- pathpath = path.Where(x => !string.IsNullOrEmpty(x)).DefaultIfEmpty().ToArray();
- Array.Resize(ref path, path.Length - 1);
- details.loaddata(path, currnt); //send detail to a class file
- }
- data.loadtosql(details.licensedetail);
- Console.WriteLine("Your output were extracted.......");
- }
- catch (Exception e)
- {
-
- string errorfolder = "Error";
- string eerror = e.Message;
- string Fname = "error";
- string Fdate = DateTime.Now.ToString("dd-MM-yyyy HH_mm_ss");
- string errorfilePath = Path.Combine(dir, errorfolder);//text file output path
- string createTextFile1 = "";
- string outPath = @"" + errorfilePath + "\\" + Fname + " " + Fdate + ".txt";
- createTextFile1 += "" + error + Environment.NewLine;
- System.IO.File.WriteAllText(outPath, createTextFile1);
- }
-
- }
- }
-
- class tosql
- {
- storedata store = new storedata();
- public void loadtosql(DataTable user)
- {
- store.BatchBulkCopyuserdetails(user);
- }
-
- }
- }
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.