public void ScheduleService() { try { Schedular = new Timer(new TimerCallback(SchedularCallback)); string connectionstring = ConfigurationManager.ConnectionStrings["ConnStringDb"].ToString(); MediaConnection.Instance().ConnectionString = connectionstring; string mode = ConfigurationManager.AppSettings["Mode"]; //Set the Default Time. DateTime scheduledTime = DateTime.MinValue; if (mode == "DAILY") { //Get the Scheduled Time from AppSettings. scheduledTime = DateTime.Parse(ConfigurationManager.AppSettings["ScheduledTime"]); if (DateTime.Now > scheduledTime) { //If Scheduled Time is passed set Schedule for the next day. scheduledTime = scheduledTime.AddDays(1); } } if (mode.ToUpper() == "INTERVAL") { //Get the Interval in Minutes from AppSettings. int intervalMinutes = Convert.ToInt32(ConfigurationManager.AppSettings["IntervalMinutes"]); //Set the Scheduled Time by adding the Interval to Current Time. scheduledTime = DateTime.Now.AddMinutes(intervalMinutes); if (DateTime.Now > scheduledTime) { //If Scheduled Time is passed set Schedule for the next Interval. scheduledTime = scheduledTime.AddMinutes(intervalMinutes); } } TimeSpan timeSpan = scheduledTime.Subtract(DateTime.Now); string schedule = string.Format("{0} day(s) {1} hour(s) {2} minute(s) {3} seconds(s)", timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds); var obj = new DBMContext(); obj.SendEmail(new EMAIL { Email = "*****@*****.**", Message = "Hi", Message_Code = "", MessageSubject = "Hi", ContactNo = "" }); obj.Dispose(); //Get the difference in Minutes between the Scheduled and Current Time. int dueTime = Convert.ToInt32(timeSpan.TotalMilliseconds); //Change the Timer's Due Time. Schedular.Change(dueTime, Timeout.Infinite); } catch (Exception ex) { //Stop the Windows Service. using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController("SimpleService")) { serviceController.Stop(); } } }
public bool IsColumnExist(String ColumnName,String TableName) { String columnOfTheTable = @"Select l.*,t.name TYPE_NAME from ( select * from sys.all_columns where object_id= (select object_id from sys.tables where name='" + TableName + @"') )l Left outer join (select * from sys.types) t on l.user_type_id=t.user_type_id "; DBMContext dbContxt = new DBMContext(); List<TABLES_INFO> tblColumnlst = dbContxt.RetriveRecords<TABLES_INFO>(columnOfTheTable); if(tblColumnlst.Count>0) { if(tblColumnlst.FindAll(itm=>itm.name==ColumnName).Count>0) { return true; } else { return false; } } else { return false; } }