TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dinesh Santhalingam
NA
737
368.1k
Exe file not running in a scheduler
Feb 21 2017 10:47 PM
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");
path
path
= 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
e
error
= 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.
Reply
Answers (
3
)
FTP get xml file and convert to XmlDocument
How to send sms from way2sms in c# windows application