I have created a windows service which has to execute a stored procedure once in every 5-10 min.
My service runs and builds without any errors but it does not execute
the stored procedure. Below is the code I have written. I dont
understand where the mistake is. Any suggestion will be really helpful.
Even URLs related to this will be great.
using System;
using System.Data;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using System.IO;
using System.Configuration;
namespace offsiteBilling
{
public partial class OffsiteAgent : ServiceBase
{
Timer sysTimer = new Timer();
private int _interval = 300000;
public OffsiteAgent()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
sysTimer.Interval = _interval;
sysTimer.Enabled = true;
sysTimer.Start();
sysTimer.Elapsed += new System.Timers.ElapsedEventHandler(onElapsed);
}
protected override void OnStop()
{
}
private void onElapsed(object sender, ElapsedEventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);
try
{
SqlCommand cmd = new SqlCommand("GetOffsiteSrvrpath", conn);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
EventLog.WriteEntry("Error", ex.Message, EventLogEntryType.Warning);
}
}
}
}
Loading

Micke BlomqvistRank #1,660 · 923 reputationPosted Feb 8, 2011, 8:49 AM EST
Jaison Ebe5 reputationPosted May 16, 2018, 1:22 AM EDT
Micke BlomqvistRank #1,660 · 923 reputationPosted Feb 15, 2011, 9:45 AM EST
Alexander Londono2 reputationPosted Apr 26, 2012, 3:28 PM EDT
Akshay D2 reputationPosted Jun 13, 2015, 4:28 AM EDT