hi there,
I am trying to make my service to insert to a database when it starts as follows :
protected override void OnStart(string[] args)
{
base.OnStart(args);
string query;
id += 1;
SqlCommand comm;
conn = new SqlConnection("my connection string");
query = "insert into myTable values('" + id + "'lamya'" + "')";
comm = new SqlCommand(query, conn);
try
{
conn.Open();
while (id >= 120)
{
comm.ExecuteScalar();
query = "insert into myTable values('" + id + "'lamya'" + "')";
comm = new SqlCommand(query, conn);
id++;
}
conn.close();
}
catch (Exception ex)
{
//throw ex;
}
}
after adding an installer and installing the service using the Installutil.exe
when I start the service from the services manager this msg shows up:
The ServiceOnTest service on your Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the performance Logs and the Alters service.
where ServiceOnTest is the service name ,
just to know if it matters: the startup type is automatically and it run for the local System
what should I do to make it work, I need it to insert to the database and more but first I need to know what wrong I did?
Urgent help is needed , please
Thanks