Hi,
I'm developing window service application on C# 2005.
The service is to read a new excel file on certain directory, and
process it to database.
The service work find on XP.
But when I install the application on Windows Server 2003, when i
start the service it said:
"The <my serviceon Local Computer started and then stop. Some
service stop automatically if they have no work to do , for example ,
the Performance Logs and Alerts System."
So my service will never run.
On my service I'm using File System Watcher Component.
What should I do?
Thanks. 8 9353
On Jul 13, 1:36*pm, Lemune <alfredosilito...@gmail.comwrote:
Hi,
I'm developing window service application on C# 2005.
The service is to read a new excel file on certain directory, and
process it to database.
The service work find on XP.
But when I install the application on Windows Server 2003, when i
start the service it said:
"The <my serviceon Local Computer started and then stop. Some
service stop automatically if they have no work to do , for example ,
the Performance Logs and Alerts System."
So my service will never run.
On my service I'm using File System Watcher Component.
It would help if you explain in more details how exactly you're using
that component (and, in general, how your service is written). Code
snippets would be even better.
Lemune wrote:
I'm developing window service application on C# 2005.
The service is to read a new excel file on certain directory, and
process it to database.
The service work find on XP.
But when I install the application on Windows Server 2003, when i
start the service it said:
"The <my serviceon Local Computer started and then stop. Some
service stop automatically if they have no work to do , for example ,
the Performance Logs and Alerts System."
This means your service crashed during startup, which could have any number
of causes. Consult the event log for more details, and hook up an event
handler to AppDomain.UnhandledException in your service that logs to a file.
--
J.
On Jul 13, 5:43*am, Jeroen Mostert <jmost...@xs4all.nlwrote:
Lemune wrote:
I'm developing window service application on C# 2005.
The service is to read a new excel file on certain directory, and
process it to database.
The service work find on XP.
But when I install the application on Windows Server 2003, when i
start the service it said:
"The <my serviceon Local Computer started and then stop. Some
service stop automatically if they have no work to do , for example ,
the Performance Logs and Alerts System."
This means your service crashed during startup, which could have any number
of causes. Consult the event log for more details, and hook up an event
handler to AppDomain.UnhandledException in your service that logs to a file.
--
J.
I can't remember for certain, but it sounds more like the service
stopped by choice. When a service crashes or throws an exception you
get a message stating that the service failed to start altogether.
Brian Gideon wrote:
On Jul 13, 5:43 am, Jeroen Mostert <jmost...@xs4all.nlwrote:
>Lemune wrote:
>>I'm developing window service application on C# 2005. The service is to read a new excel file on certain directory, and process it to database. The service work find on XP. But when I install the application on Windows Server 2003, when i start the service it said: "The <my serviceon Local Computer started and then stop. Some service stop automatically if they have no work to do , for example , the Performance Logs and Alerts System."
This means your service crashed during startup, which could have any number of causes. Consult the event log for more details, and hook up an event handler to AppDomain.UnhandledException in your service that logs to a file.
I can't remember for certain, but it sounds more like the service
stopped by choice. When a service crashes or throws an exception you
get a message stating that the service failed to start altogether.
Not on Windows XP, at least; I tested it. If the service throws an exception
in its OnStart(), you'll get the exact message the OP described. The event
log will contain the exception details.
A .NET service can't really stop by choice, except through calling
Environment.Exit() (or by explicitly connecting to the SCM and stopping
itself, but that's just backwards).
--
J.
Thanks all for your quict reply
this is my snipped code ( I just translate it because i use my on
language) -
public partial class HCCPReader : ServiceBase
-
{
-
DateTime _lastFileTime = DateTime.MinValue;
-
protected DateTime _lastFTPTime = DateTime.MinValue;
-
protected DateTime _lastUploadTime = DateTime.MinValue;
-
protected DateTime _lastBankUploadTime = DateTime.MinValue;
-
-
System.Timers.Timer _newTimer = new System.Timers.Timer();
-
-
public HCCPReader()
-
{
-
InitializeComponent();
-
}
-
-
protected override void OnStart(string[] args)
-
{
-
// TODO: Add code here to start your service.
-
_lastFileTime = DateTime.MinValue;
-
fswUpload.Path = Common.GetUploadSettlementPath();
-
fswUpload.EnableRaisingEvents = true;
-
fswFtp.Path = Common.GetFTPPath();
-
fswFtp.EnableRaisingEvents = true;
-
fswBankNotify.Path = Common.GetUploadBankPath();
-
fswBankNotify.EnableRaisingEvents=true;
-
_newTimer.Interval =3600000;
-
_newTimer.Elapsed += new
-
System.Timers.ElapsedEventHandler(ServiceTimer_Tick);
-
}
-
-
protected override void OnStop()
-
{
-
// TODO: Add code here to perform any tear-down necessary to stop
-
your service.
-
fswUpload.EnableRaisingEvents = false;
-
fswFtp.EnableRaisingEvents = false;
-
fswBankNotify.EnableRaisingEvents = false;
-
}
-
-
private void ServiceTimer_Tick(object sender,
-
System.Timers.ElapsedEventArgs e)
-
{
-
SunFile.Clear();
-
Clear.ClearDirectory();
-
}
-
private void fswFtp_Changed(object sender,
-
System.IO.FileSystemEventArgs e)
-
{
-
DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
-
DataTable _dataExcel = new DataTable();
-
try
-
{
-
if (_fswFileTime _lastFTPTime)
-
{
-
_lastFTPTime = _fswFileTime;
-
bool _isFileComplete = Common.IsFileCompete(e.FullPath);
-
int _tries = 0;
-
while (!_isFileComplete && _tries < 15)
-
{
-
System.Threading.Thread.Sleep(1000);
-
_tries++;
-
_isFileComplete = Common.IsFileCompete(e.FullPath);
-
}
-
if (_isFileComplete)
-
{
-
//here sistem to read excel file
-
_dataExcel = Reading.GetDataExcel(e.FullPath);
-
//column 10
-
string[] _arrayFileName = e.Name.Split('_');
-
Decimal _fileTotal = 0;
-
Decimal _totalAmount = 0;
-
try
-
{
-
_fileTotal = Convert.ToDecimal(_arrayFileName[3]);
-
}
-
catch
-
{
-
_fileTotal = -1;
-
TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
-
with file name template.");
-
}
-
if (_fileTotal != -1)
-
{
-
foreach (DataRow _record in _dataExcel.Rows)
-
{
-
if (_record[0].ToString() == "S" || _record[0].ToString() == "Z" ||
-
_record[0].ToString() == "T" || _record[0].ToString() == "P")
-
{
-
_totalAmount += Convert.ToDecimal(_record[11]);
-
}
-
}
-
if (_fileTotal != _totalAmount)
-
{
-
TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName (" +
-
_fileTotal.ToString() +
-
") is diffrent with file content (" + _totalAmount.ToString() +
-
".");
-
}
-
else
-
{
-
Status _insertMessage = new Status();
-
if (Common.IsInActiveDate(_arrayFileName[2]))
-
{
-
_insertMessage = Settlement.Inserts(_dataExcel);
-
}
-
else
-
{
-
_insertMessage = Settlement.Inserts(_dataExcel, true);
-
}
-
if (_insertMessage.StatusValue)
-
{
-
TReadingLog.Add(e.Name, "Success", "Data settlement has been
-
inserted. " + _insertMessage.Remark);
-
}
-
else
-
{
-
TReadingLog.Add(e.Name, "Failed", "Data settlement failed to be
-
inserted. " + _insertMessage.Remark);
-
}
-
}
-
}
-
}
-
else
-
{
-
_lastFTPTime = DateTime.MinValue;
-
}
-
-
}
-
}
-
catch (Exception _error)
-
{
-
TLog.Add("HCCPReader.HCCPReader.fswFtp_Changed", _error.Message);
-
}
-
finally
-
{
-
_dataExcel.Dispose();
-
}
-
}
-
-
private void fswUpload_Changed(object sender, FileSystemEventArgs e)
-
{
-
DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
-
DataTable _dataExcel = new DataTable();
-
try
-
{
-
if (_fswFileTime _lastFTPTime)
-
{
-
_lastFTPTime = _fswFileTime;
-
bool _isFileComplete = Common.IsFileCompete(e.FullPath);
-
int _tries = 0;
-
while (!_isFileComplete && _tries < 15)
-
{
-
System.Threading.Thread.Sleep(1000);
-
_tries++;
-
_isFileComplete = Common.IsFileCompete(e.FullPath);
-
}
-
if (_isFileComplete)
-
{
-
//here sistem to read excel file
-
_dataExcel = Reading.GetDataExcel(e.FullPath);
-
//column 10
-
string[] _arrayFileName = e.Name.Split('_');
-
Decimal _fileTotal = 0;
-
Decimal _totalAmount = 0;
-
try
-
{
-
_fileTotal = Convert.ToDecimal(_arrayFileName[3]);
-
}
-
catch
-
{
-
_fileTotal = -1;
-
TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
-
with file name template.");
-
}
-
if (_fileTotal != -1)
-
{
-
foreach (DataRow _record in _dataExcel.Rows)
-
{
-
if (_record[0].ToString() == "S" || _record[0].ToString() == "Z" ||
-
_record[0].ToString() == "T" || _record[0].ToString() == "P")
-
{
-
_totalAmount += Convert.ToDecimal(_record[11]);
-
}
-
}
-
if (_fileTotal != _totalAmount)
-
{
-
TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName (" +
-
_fileTotal.ToString() +
-
") is diffrent with file content (" + _totalAmount.ToString() +
-
".");
-
}
-
else
-
{
-
Status _insertMessage = new Status();
-
if (Common.IsInActiveDate(_arrayFileName[2]))
-
{
-
_insertMessage = Settlement.Inserts(_dataExcel);
-
}
-
else
-
{
-
_insertMessage = Settlement.Inserts(_dataExcel, true);
-
}
-
if (_insertMessage.StatusValue)
-
{
-
TReadingLog.Add(e.Name, "Success", "Data settlement has been
-
inserted. " + _insertMessage.Remark);
-
}
-
else
-
{
-
TReadingLog.Add(e.Name, "Failed", "Data settlement failed to be
-
inserted. " + _insertMessage.Remark);
-
}
-
}
-
}
-
}
-
else
-
{
-
_lastFTPTime = DateTime.MinValue;
-
}
-
-
}
-
}
-
catch (Exception _error)
-
{
-
TLog.Add("HCCPReader.HCCPReader.fswUpload_Changed", _error.Message);
-
}
-
finally
-
{
-
_dataExcel.Dispose();
-
}
-
}
-
-
private void fswFtp_Created(object sender, FileSystemEventArgs e)
-
{
-
DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
-
DataTable _dataExcel = new DataTable();
-
try
-
{
-
bool _isFileComplete = Common.IsFileCompete(e.FullPath);
-
if (_isFileComplete)
-
{
-
//here sistem to read excel file
-
_dataExcel = Reading.GetDataExcel(e.FullPath);
-
string[] _arrayFileName = e.Name.Split('_');
-
Decimal _fileTotal = 0;
-
Decimal _totalAmount = 0;
-
try
-
{
-
_fileTotal = Convert.ToDecimal(_arrayFileName[3]);
-
}
-
catch
-
{
-
_fileTotal = -1;
-
TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
-
with file name template.");
-
}
-
if (_fileTotal != -1)
-
{
-
foreach (DataRow _record in _dataExcel.Rows)
-
{
-
if (_record[0].ToString() == "S" || _record[0].ToString() == "Z"
-
|| _record[0].ToString() == "T" || _record[0].ToString() == "P")
-
{
-
_totalAmount += Convert.ToDecimal(_record[11]);
-
}
-
}
-
if (_fileTotal != _totalAmount)
-
{
-
TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName
-
(" + _fileTotal.ToString() +
-
") is diffrent with file content (" + _totalAmount.ToString() +
-
".");
-
}
-
else
-
{
-
Status _insertMessage = new Status();
-
if (Common.IsInActiveDate(_arrayFileName[2]))
-
{
-
_insertMessage = Settlement.Inserts(_dataExcel);
-
}
-
else
-
{
-
_insertMessage = Settlement.Inserts(_dataExcel, true);
-
}
-
if (_insertMessage.StatusValue)
-
{
-
TReadingLog.Add(e.Name, "Success", "Data settlement has been
-
inserted. " + _insertMessage.Remark);
-
}
-
else
-
{
-
TReadingLog.Add(e.Name, "Failed", "Data settlement failed to be
-
inserted. " + _insertMessage.Remark);
-
}
-
}
-
}
-
}
-
}
-
catch (Exception _error)
-
{
-
TLog.Add("HCCPReader.HCCPReader.fswFtp_Created", _error.Message);
-
}
-
finally
-
{
-
_dataExcel.Dispose();
-
}
-
}
-
-
private void fswUpload_Created(object sender, FileSystemEventArgs e)
-
{
-
DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
-
DataTable _dataExcel = new DataTable();
-
try
-
{
-
bool _isFileComplete = Common.IsFileCompete(e.FullPath);
-
if (_isFileComplete)
-
{
-
//here sistem to read excel file
-
_dataExcel = Reading.GetDataExcel(e.FullPath);
-
string[] _arrayFileName = e.Name.Split('_');
-
Decimal _fileTotal = 0;
-
Decimal _totalAmount = 0;
-
try
-
{
-
_fileTotal = Convert.ToDecimal(_arrayFileName[3]);
-
}
-
catch
-
{
-
_fileTotal = -1;
-
TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
-
with file name template.");
-
}
-
if (_fileTotal != -1)
-
{
-
foreach (DataRow _record in _dataExcel.Rows)
-
{
-
if (_record[0].ToString() == "S" || _record[0].ToString() == "Z"
-
|| _record[0].ToString() == "T" || _record[0].ToString() == "P")
-
{
-
_totalAmount += Convert.ToDecimal(_record[11]);
-
}
-
}
-
if (_fileTotal != _totalAmount)
-
{
-
TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName
-
(" + _fileTotal.ToString() +
-
") is diffrent with file content (" + _totalAmount.ToString() +
-
".");
-
}
-
else
-
{
-
-
Status _insertMessage = new Status();
-
if(Common.IsInActiveDate(_arrayFileName[2]))
-
{
-
_insertMessage=Settlement.Inserts(_dataExcel);
-
}
-
else
-
{
-
_insertMessage=Settlement.Inserts(_dataExcel,true);
-
}
-
if (_insertMessage.StatusValue)
-
{
-
TReadingLog.Add(e.Name,"Success", "Data settlement has been
-
inserted. " + _insertMessage.Remark);
-
}
-
else
-
{
-
TReadingLog.Add(e.Name,"Failed", "Data settlement failed to be
-
inserted. " + _insertMessage.Remark);
-
}
-
}
-
}
-
}
-
}
-
catch (Exception _error)
-
{
-
TLog.Add("HCCPReader.HCCPReader.fswUpload_Created", _error.Message);
-
}
-
finally
-
{
-
_dataExcel.Dispose();
-
}
-
}
-
-
private void fswBankNotify_Changed(object sender, FileSystemEventArgs
-
e)
-
{
-
DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
-
DataTable _dataExcel = new DataTable();
-
try
-
{
-
if (_fswFileTime _lastBankUploadTime)
-
{
-
_lastBankUploadTime = _fswFileTime;
-
bool _isFileComplete = Common.IsFileCompete(e.FullPath);
-
int _tries = 0;
-
while (!_isFileComplete && _tries < 15)
-
{
-
System.Threading.Thread.Sleep(1000);
-
_tries++;
-
_isFileComplete = Common.IsFileCompete(e.FullPath);
-
}
-
if (_isFileComplete)
-
{
-
//here sistem to read excel file
-
_dataExcel = Reading.GetDataExcel(e.FullPath);
-
Status _insertMessage = new Status();
-
_insertMessage = BankNotification.Process(_dataExcel);
-
if (_insertMessage.StatusValue)
-
{
-
TReadingLog.Add(e.Name, "Success", "Data bank notification
-
berhasil diinput. " + _insertMessage.Remark);
-
}
-
else
-
{
-
TReadingLog.Add(e.Name, "Failed", "Data bank notification gagal
-
diinput. " + _insertMessage.Remark);
-
}
-
FileInfo _fileInfo = new FileInfo(e.FullPath);
-
TTempBankNotification.UpdateStatus(_fileInfo.DirectoryName,
-
_insertMessage);
-
File.Delete(e.FullPath);
-
}
-
else
-
{
-
_lastFTPTime = DateTime.MinValue;
-
}
-
}
-
}
-
catch (Exception _error)
-
{
-
TLog.Add("HCCPReader.HCCPReader.fswBankNotify_Changed",
-
_error.Message);
-
}
-
finally
-
{
-
_dataExcel.Dispose();
-
}
-
}
-
-
private void fswBankNotify_Created(object sender, FileSystemEventArgs
-
e)
-
{
-
DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
-
DataTable _dataExcel = new DataTable();
-
try
-
{
-
bool _isFileComplete = Common.IsFileCompete(e.FullPath);
-
if (_isFileComplete)
-
{
-
//here sistem to read excel file
-
_dataExcel = Reading.GetDataExcel(e.FullPath);
-
Status _insertMessage = new Status();
-
_insertMessage = BankNotification.Process(_dataExcel);
-
if (_insertMessage.StatusValue)
-
{
-
TReadingLog.Add(e.Name, "Success", "Data bank notification berhasil
-
diinput. " + _insertMessage.Remark);
-
}
-
else
-
{
-
TReadingLog.Add(e.Name, "Failed", "Data bank notification gagal
-
diinput. " + _insertMessage.Remark);
-
}
-
FileInfo _fileInfo= new FileInfo(e.FullPath);
-
TTempBankNotification.UpdateStatus(_fileInfo.DirectoryName,
-
_insertMessage);
-
File.Delete(e.FullPath);
-
}
-
}
-
catch (Exception _error)
-
{
-
TLog.Add("HCCPReader.HCCPReader.fswBankNotify_Created",
-
_error.Message);
-
}
-
finally
-
{
-
_dataExcel.Dispose();
-
}
-
}
-
}
-
-
My code just run well on MS XP, but it has this problem on MS Server
2003
Thanks all for your quict reply
this is my snipped code ( I just translate it because i use my on
language) -
public partial class HCCPReader : ServiceBase
-
{
-
DateTime _lastFileTime = DateTime.MinValue;
-
protected DateTime _lastFTPTime = DateTime.MinValue;
-
protected DateTime _lastUploadTime = DateTime.MinValue;
-
protected DateTime _lastBankUploadTime = DateTime.MinValue;
-
-
System.Timers.Timer _newTimer = new System.Timers.Timer();
-
-
public HCCPReader()
-
{
-
InitializeComponent();
-
}
-
-
protected override void OnStart(string[] args)
-
{
-
// TODO: Add code here to start your service.
-
_lastFileTime = DateTime.MinValue;
-
fswUpload.Path = Common.GetUploadSettlementPath();
-
fswUpload.EnableRaisingEvents = true;
-
fswFtp.Path = Common.GetFTPPath();
-
fswFtp.EnableRaisingEvents = true;
-
fswBankNotify.Path = Common.GetUploadBankPath();
-
fswBankNotify.EnableRaisingEvents=true;
-
_newTimer.Interval =3600000;
-
_newTimer.Elapsed += new
-
System.Timers.ElapsedEventHandler(ServiceTimer_Tick);
-
}
-
-
protected override void OnStop()
-
{
-
// TODO: Add code here to perform any tear-down necessary to stop
-
your service.
-
fswUpload.EnableRaisingEvents = false;
-
fswFtp.EnableRaisingEvents = false;
-
fswBankNotify.EnableRaisingEvents = false;
-
}
-
-
private void ServiceTimer_Tick(object sender,
-
System.Timers.ElapsedEventArgs e)
-
{
-
SunFile.Clear();
-
Clear.ClearDirectory();
-
}
-
private void fswFtp_Changed(object sender,
-
System.IO.FileSystemEventArgs e)
-
{
-
DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
-
DataTable _dataExcel = new DataTable();
-
try
-
{
-
if (_fswFileTime _lastFTPTime)
-
{
-
_lastFTPTime = _fswFileTime;
-
bool _isFileComplete = Common.IsFileCompete(e.FullPath);
-
int _tries = 0;
-
while (!_isFileComplete && _tries < 15)
-
{
-
System.Threading.Thread.Sleep(1000);
-
_tries++;
-
_isFileComplete = Common.IsFileCompete(e.FullPath);
-
}
-
if (_isFileComplete)
-
{
-
//here sistem to read excel file
-
_dataExcel = Reading.GetDataExcel(e.FullPath);
-
//column 10
-
string[] _arrayFileName = e.Name.Split('_');
-
Decimal _fileTotal = 0;
-
Decimal _totalAmount = 0;
-
try
-
{
-
_fileTotal = Convert.ToDecimal(_arrayFileName[3]);
-
}
-
catch
-
{
-
_fileTotal = -1;
-
TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
-
with file name template.");
-
}
-
if (_fileTotal != -1)
-
{
-
foreach (DataRow _record in _dataExcel.Rows)
-
{
-
if (_record[0].ToString() == "S" || _record[0].ToString() == "Z" ||
-
_record[0].ToString() == "T" || _record[0].ToString() == "P")
-
{
-
_totalAmount += Convert.ToDecimal(_record[11]);
-
}
-
}
-
if (_fileTotal != _totalAmount)
-
{
-
TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName (" +
-
_fileTotal.ToString() +
-
") is diffrent with file content (" + _totalAmount.ToString() +
-
".");
-
}
-
else
-
{
-
Status _insertMessage = new Status();
-
if (Common.IsInActiveDate(_arrayFileName[2]))
-
{
-
_insertMessage = Settlement.Inserts(_dataExcel);
-
}
-
else
-
{
-
_insertMessage = Settlement.Inserts(_dataExcel, true);
-
}
-
if (_insertMessage.StatusValue)
-
{
-
TReadingLog.Add(e.Name, "Success", "Data settlement has been
-
inserted. " + _insertMessage.Remark);
-
}
-
else
-
{
-
TReadingLog.Add(e.Name, "Failed", "Data settlement failed to be
-
inserted. " + _insertMessage.Remark);
-
}
-
}
-
}
-
}
-
else
-
{
-
_lastFTPTime = DateTime.MinValue;
-
}
-
-
}
-
}
-
catch (Exception _error)
-
{
-
TLog.Add("HCCPReader.HCCPReader.fswFtp_Changed", _error.Message);
-
}
-
finally
-
{
-
_dataExcel.Dispose();
-
}
-
}
-
-
private void fswUpload_Changed(object sender, FileSystemEventArgs e)
-
{
-
DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
-
DataTable _dataExcel = new DataTable();
-
try
-
{
-
if (_fswFileTime _lastFTPTime)
-
{
-
_lastFTPTime = _fswFileTime;
-
bool _isFileComplete = Common.IsFileCompete(e.FullPath);
-
int _tries = 0;
-
while (!_isFileComplete && _tries < 15)
-
{
-
System.Threading.Thread.Sleep(1000);
-
_tries++;
-
_isFileComplete = Common.IsFileCompete(e.FullPath);
-
}
-
if (_isFileComplete)
-
{
-
//here sistem to read excel file
-
_dataExcel = Reading.GetDataExcel(e.FullPath);
-
//column 10
-
string[] _arrayFileName = e.Name.Split('_');
-
Decimal _fileTotal = 0;
-
Decimal _totalAmount = 0;
-
try
-
{
-
_fileTotal = Convert.ToDecimal(_arrayFileName[3]);
-
}
-
catch
-
{
-
_fileTotal = -1;
-
TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
-
with file name template.");
-
}
-
if (_fileTotal != -1)
-
{
-
foreach (DataRow _record in _dataExcel.Rows)
-
{
-
if (_record[0].ToString() == "S" || _record[0].ToString() == "Z" ||
-
_record[0].ToString() == "T" || _record[0].ToString() == "P")
-
{
-
_totalAmount += Convert.ToDecimal(_record[11]);
-
}
-
}
-
if (_fileTotal != _totalAmount)
-
{
-
TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName (" +
-
_fileTotal.ToString() +
-
") is diffrent with file content (" + _totalAmount.ToString() +
-
".");
-
}
-
else
-
{
-
Status _insertMessage = new Status();
-
if (Common.IsInActiveDate(_arrayFileName[2]))
-
{
-
_insertMessage = Settlement.Inserts(_dataExcel);
-
}
-
else
-
{
-
_insertMessage = Settlement.Inserts(_dataExcel, true);
-
}
-
if (_insertMessage.StatusValue)
-
{
-
TReadingLog.Add(e.Name, "Success", "Data settlement has been
-
inserted. " + _insertMessage.Remark);
-
}
-
else
-
{
-
TReadingLog.Add(e.Name, "Failed", "Data settlement failed to be
-
inserted. " + _insertMessage.Remark);
-
}
-
}
-
}
-
}
-
else
-
{
-
_lastFTPTime = DateTime.MinValue;
-
}
-
-
}
-
}
-
catch (Exception _error)
-
{
-
TLog.Add("HCCPReader.HCCPReader.fswUpload_Changed", _error.Message);
-
}
-
finally
-
{
-
_dataExcel.Dispose();
-
}
-
}
-
-
private void fswFtp_Created(object sender, FileSystemEventArgs e)
-
{
-
DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
-
DataTable _dataExcel = new DataTable();
-
try
-
{
-
bool _isFileComplete = Common.IsFileCompete(e.FullPath);
-
if (_isFileComplete)
-
{
-
//here sistem to read excel file
-
_dataExcel = Reading.GetDataExcel(e.FullPath);
-
string[] _arrayFileName = e.Name.Split('_');
-
Decimal _fileTotal = 0;
-
Decimal _totalAmount = 0;
-
try
-
{
-
_fileTotal = Convert.ToDecimal(_arrayFileName[3]);
-
}
-
catch
-
{
-
_fileTotal = -1;
-
TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
-
with file name template.");
-
}
-
if (_fileTotal != -1)
-
{
-
foreach (DataRow _record in _dataExcel.Rows)
-
{
-
if (_record[0].ToString() == "S" || _record[0].ToString() == "Z"
-
|| _record[0].ToString() == "T" || _record[0].ToString() == "P")
-
{
-
_totalAmount += Convert.ToDecimal(_record[11]);
-
}
-
}
-
if (_fileTotal != _totalAmount)
-
{
-
TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName
-
(" + _fileTotal.ToString() +
-
") is diffrent with file content (" + _totalAmount.ToString() +
-
".");
-
}
-
else
-
{
-
Status _insertMessage = new Status();
-
if (Common.IsInActiveDate(_arrayFileName[2]))
-
{
-
_insertMessage = Settlement.Inserts(_dataExcel);
-
}
-
else
-
{
-
_insertMessage = Settlement.Inserts(_dataExcel, true);
-
}
-
if (_insertMessage.StatusValue)
-
{
-
TReadingLog.Add(e.Name, "Success", "Data settlement has been
-
inserted. " + _insertMessage.Remark);
-
}
-
else
-
{
-
TReadingLog.Add(e.Name, "Failed", "Data settlement failed to be
-
inserted. " + _insertMessage.Remark);
-
}
-
}
-
}
-
}
-
}
-
catch (Exception _error)
-
{
-
TLog.Add("HCCPReader.HCCPReader.fswFtp_Created", _error.Message);
-
}
-
finally
-
{
-
_dataExcel.Dispose();
-
}
-
}
-
-
private void fswUpload_Created(object sender, FileSystemEventArgs e)
-
{
-
DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
-
DataTable _dataExcel = new DataTable();
-
try
-
{
-
bool _isFileComplete = Common.IsFileCompete(e.FullPath);
-
if (_isFileComplete)
-
{
-
//here sistem to read excel file
-
_dataExcel = Reading.GetDataExcel(e.FullPath);
-
string[] _arrayFileName = e.Name.Split('_');
-
Decimal _fileTotal = 0;
-
Decimal _totalAmount = 0;
-
try
-
{
-
_fileTotal = Convert.ToDecimal(_arrayFileName[3]);
-
}
-
catch
-
{
-
_fileTotal = -1;
-
TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
-
with file name template.");
-
}
-
if (_fileTotal != -1)
-
{
-
foreach (DataRow _record in _dataExcel.Rows)
-
{
-
if (_record[0].ToString() == "S" || _record[0].ToString() == "Z"
-
|| _record[0].ToString() == "T" || _record[0].ToString() == "P")
-
{
-
_totalAmount += Convert.ToDecimal(_record[11]);
-
}
-
}
-
if (_fileTotal != _totalAmount)
-
{
-
TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName
-
(" + _fileTotal.ToString() +
-
") is diffrent with file content (" + _totalAmount.ToString() +
-
".");
-
}
-
else
-
{
-
-
Status _insertMessage = new Status();
-
if(Common.IsInActiveDate(_arrayFileName[2]))
-
{
-
_insertMessage=Settlement.Inserts(_dataExcel);
-
}
-
else
-
{
-
_insertMessage=Settlement.Inserts(_dataExcel,true);
-
}
-
if (_insertMessage.StatusValue)
-
{
-
TReadingLog.Add(e.Name,"Success", "Data settlement has been
-
inserted. " + _insertMessage.Remark);
-
}
-
else
-
{
-
TReadingLog.Add(e.Name,"Failed", "Data settlement failed to be
-
inserted. " + _insertMessage.Remark);
-
}
-
}
-
}
-
}
-
}
-
catch (Exception _error)
-
{
-
TLog.Add("HCCPReader.HCCPReader.fswUpload_Created", _error.Message);
-
}
-
finally
-
{
-
_dataExcel.Dispose();
-
}
-
}
-
-
private void fswBankNotify_Changed(object sender, FileSystemEventArgs
-
e)
-
{
-
DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
-
DataTable _dataExcel = new DataTable();
-
try
-
{
-
if (_fswFileTime _lastBankUploadTime)
-
{
-
_lastBankUploadTime = _fswFileTime;
-
bool _isFileComplete = Common.IsFileCompete(e.FullPath);
-
int _tries = 0;
-
while (!_isFileComplete && _tries < 15)
-
{
-
System.Threading.Thread.Sleep(1000);
-
_tries++;
-
_isFileComplete = Common.IsFileCompete(e.FullPath);
-
}
-
if (_isFileComplete)
-
{
-
//here sistem to read excel file
-
_dataExcel = Reading.GetDataExcel(e.FullPath);
-
Status _insertMessage = new Status();
-
_insertMessage = BankNotification.Process(_dataExcel);
-
if (_insertMessage.StatusValue)
-
{
-
TReadingLog.Add(e.Name, "Success", "Data bank notification
-
berhasil diinput. " + _insertMessage.Remark);
-
}
-
else
-
{
-
TReadingLog.Add(e.Name, "Failed", "Data bank notification gagal
-
diinput. " + _insertMessage.Remark);
-
}
-
FileInfo _fileInfo = new FileInfo(e.FullPath);
-
TTempBankNotification.UpdateStatus(_fileInfo.DirectoryName,
-
_insertMessage);
-
File.Delete(e.FullPath);
-
}
-
else
-
{
-
_lastFTPTime = DateTime.MinValue;
-
}
-
}
-
}
-
catch (Exception _error)
-
{
-
TLog.Add("HCCPReader.HCCPReader.fswBankNotify_Changed",
-
_error.Message);
-
}
-
finally
-
{
-
_dataExcel.Dispose();
-
}
-
}
-
-
private void fswBankNotify_Created(object sender, FileSystemEventArgs
-
e)
-
{
-
DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
-
DataTable _dataExcel = new DataTable();
-
try
-
{
-
bool _isFileComplete = Common.IsFileCompete(e.FullPath);
-
if (_isFileComplete)
-
{
-
//here sistem to read excel file
-
_dataExcel = Reading.GetDataExcel(e.FullPath);
-
Status _insertMessage = new Status();
-
_insertMessage = BankNotification.Process(_dataExcel);
-
if (_insertMessage.StatusValue)
-
{
-
TReadingLog.Add(e.Name, "Success", "Data bank notification berhasil
-
diinput. " + _insertMessage.Remark);
-
}
-
else
-
{
-
TReadingLog.Add(e.Name, "Failed", "Data bank notification gagal
-
diinput. " + _insertMessage.Remark);
-
}
-
FileInfo _fileInfo= new FileInfo(e.FullPath);
-
TTempBankNotification.UpdateStatus(_fileInfo.DirectoryName,
-
_insertMessage);
-
File.Delete(e.FullPath);
-
}
-
}
-
catch (Exception _error)
-
{
-
TLog.Add("HCCPReader.HCCPReader.fswBankNotify_Created",
-
_error.Message);
-
}
-
finally
-
{
-
_dataExcel.Dispose();
-
}
-
}
-
}
-
-
My code just run well on MS XP, but it has this problem on MS Server
2003
On Jul 13, 2:50*pm, Jeroen Mostert <jmost...@xs4all.nlwrote:
Brian Gideon wrote:
On Jul 13, 5:43 am, Jeroen Mostert <jmost...@xs4all.nlwrote:
Lemune wrote: I'm developing window service application on C# 2005. The service is to read a new excel file on certain directory, and process it to database. The service work find on XP. But when I install the application on Windows Server 2003, when i start the service it said: "The <my serviceon Local Computer started and then stop. Some service stop automatically if they have no work to do , for example , the Performance Logs and Alerts System."
This means your service crashed during startup, which could have any number
of causes. Consult the event log for more details, and hook up an event
handler to AppDomain.UnhandledException in your service that logs to afile.
I can't remember for certain, but it sounds more like the service
stopped by choice. *When a service crashes or throws an exception you
get a message stating that the service failed to start altogether.
Not on Windows XP, at least; I tested it. If the service throws an exception
in its OnStart(), you'll get the exact message the OP described. The event
log will contain the exception details.
A .NET service can't really stop by choice, except through calling
Environment.Exit() (or by explicitly connecting to the SCM and stopping
itself, but that's just backwards).
--
J.
Yep, I tested it too. You are correct. I guess my memory isn't that
good :)
Thanks Jeroen,
I check event log, and I have found my error.
It's just because the my exe config that has some error.
I have fixed my problem.
Thanks all. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Weng kin |
last post by:
Hi everyone,
I have a problem trying to load an image without the image resizing
itself to fit into the window. My simple javascript is as follows:
function viewImage(filename)
{
features =...
|
by: Marcus Otmarsen |
last post by:
During the last months I obeserved a growing number of web pages with popups
inside a web page. I don't know the technique by which these in-page-windows
are implemented (either Javascript or...
|
by: Gayathri |
last post by:
Is there anyway to disable the stop button in IE 6?
Without doing "Opening in new window and toolbar is set to no"
what will document.onstop help in??
I need to capture the browser stop...
|
by: Joe |
last post by:
Dear Friends,
How to run the C# Console application as services?
I have a console application.I want run this application as background
services.User don't want see the command propmt.
If anyone...
|
by: Frank Rizzo |
last post by:
Hello,
My c# based windows service takes a while to dispose. I have to release
bunch of resources all over the place and unfortunately it can take
20-40 seconds before I can cleanly exit.
...
|
by: Ike |
last post by:
Does anyone know how to disable a list box element in VB 6 ? Thanks Ike
|
by: srcleveland |
last post by:
I am trying to have a windows service stop itself. I am currently
using the following code but I would like to find a way to stop the
service without having to shell out to a command prompt
...
|
by: darthghandi |
last post by:
I've created a class to listen to all interfaces and do a
BeginAccept(). Once it gets a connection, it passes the connected
socket off and stores it in a List. Next, it continues to listen for...
|
by: myjish18 |
last post by:
Hello,
We have a DB2 UDB database v8.2.7 (db2 v8.2 fixpak 14) on AIX 5.3
which has Automatic Storage (AS) enabled. We want to disable
automatic storage on entire database and/or disable...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |