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
Somen Natta
NA
33
3.7k
insert csv file into sql table using windows service
Apr 21 2021 10:29 AM
I have a method A1 in the class service2021.cs which is not being either called or executed. Can anyone tell me why?
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Data.SqlClient;
using
System.Diagnostics;
using
System.Linq;
using
System.ServiceProcess;
using
System.Text;
using
System.Threading.Tasks;
using
System.Configuration;
using
System.IO;
using
System.Timers;
namespace
InsertCsvIntoDatabaseTable
{
public
partial
class
Service2021 : ServiceBase
{
Timer timer =
new
Timer();
public
Service2021()
{
InitializeComponent();
//A1();
}
protected
override
void
OnStart(
string
[] args)
{
WriteToFile(
"Service is started at "
+ DateTime.Now);
timer.Elapsed +=
new
ElapsedEventHandler(OnElapsedTime);
WriteToFile(
"After ElapsedEventHandler in OnStart "
+ DateTime.Now);
timer.Interval = 30000;
WriteToFile(
"After timer Interval in OnStart "
+ DateTime.Now);
timer.Enabled =
true
;
WriteToFile(
"After timer Enabled in OnStart "
+ DateTime.Now);
}
protected
override
void
OnStop()
{
WriteToFile(
"Service is stopped at "
+ DateTime.Now);
}
private
void
OnElapsedTime(
object
source, ElapsedEventArgs e)
{
//WriteToFile("Service is recall at before A1 method" + DateTime.Now);
A1();
WriteToFile(
"Service is recall at after A1 method"
+ DateTime.Now);
}
public
void
WriteToFile(
string
Message)
{
string
path = AppDomain.CurrentDomain.BaseDirectory +
"\\Logs"
;
if
(!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string
filepath = AppDomain.CurrentDomain.BaseDirectory +
"\\Logs\\ServiceLog_"
+ DateTime.Now.Date.ToShortDateString().Replace(
'/'
,
'_'
) +
".txt"
;
if
(!File.Exists(filepath))
{
// Create a file to write to.
using
(StreamWriter sw = File.CreateText(filepath))
{
sw.WriteLine(Message);
}
}
else
{
using
(StreamWriter sw = File.AppendText(filepath))
{
sw.WriteLine(Message);
}
}
}
public
void
A1()
{
Class2 ob =
new
Class2();
//ob.InsertExcelRecords(CSVFilePath);
ob.InsertExcelRecords();
}
}
}
Reply
Answers (
2
)
Windows service is not installing in server
total income and salary by specific date in winsform database