Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
AnswerRe: About Creating Forum with asp.net c# Pin
sankarsan parida7-Oct-14 18:36
professionalsankarsan parida7-Oct-14 18:36 
QuestionDisabling DataGridView Column Button after clicking it Pin
AMRITESH ASTHANA6-Oct-14 1:11
AMRITESH ASTHANA6-Oct-14 1:11 
AnswerRe: Disabling DataGridView Column Button after clicking it Pin
Eddy Vluggen6-Oct-14 8:21
professionalEddy Vluggen6-Oct-14 8:21 
GeneralRe: Disabling DataGridView Column Button after clicking it Pin
AMRITESH ASTHANA6-Oct-14 21:29
AMRITESH ASTHANA6-Oct-14 21:29 
GeneralRe: Disabling DataGridView Column Button after clicking it Pin
Eddy Vluggen6-Oct-14 22:31
professionalEddy Vluggen6-Oct-14 22:31 
QuestionHow to add my app written by C# into Microsoft word as add-in? Pin
nashalj5-Oct-14 21:23
nashalj5-Oct-14 21:23 
AnswerRe: How to add my app written by C# into Microsoft word as add-in? Pin
BillWoodruff5-Oct-14 21:56
professionalBillWoodruff5-Oct-14 21:56 
QuestionIssue regarding SQLDependency used in Windows Service Pin
Tridip Bhattacharjee5-Oct-14 21:09
professionalTridip Bhattacharjee5-Oct-14 21:09 
here i have attached my full code. i wrote SqlDependency related code in windows service which will fire mail when any data change found in a specific table in database. when i start my service then it is working fine. suppose when i start my service and after that when i change data in table then i saw mail is coming but from the next day when i change data in table then i am not getting any mail. some how SqlDependency is getting freeze or stuck but i am not being able to catch where is the problem lies in the code.

so please see my windows service code and guide me where i am making the mistake for which SqlDependency is not working every time properly.
C#
public partial class PartIndexer : ServiceBase
    {
        static string connectionString = "MyConnection String;Pooling=true;Connect Timeout=20;";
        SqlDependency dep;

        public PartIndexer()
        {
            InitializeComponent();
        }

        #region OnStart
        protected override void OnStart(string[] args)
        {
            System.Data.SqlClient.SqlDependency.Stop(connectionString);
            System.Data.SqlClient.SqlDependency.Start(connectionString);
            RegisterNotification();
            MailNotify("STARTED");
        }
        #endregion

        #region RegisterNotification
        /// <summary>
        /// RegisterNotification
        /// this is main routine which will monitor data change in ContentChangeLog table
        /// </summary>
        private void RegisterNotification()
        {
            string tmpdata = "";
            //eventLog1.WriteEntry("RegisterNotification invoked"); 

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = conn.CreateCommand();
                    cmd.CommandText = "SELECT ActivityDate FROM [bba-reman].ContentChangeLog";
                    dep = new SqlDependency(cmd);
                    dep.OnChange += new OnChangeEventHandler(OnDataChange);
                    SqlDataReader dr = cmd.ExecuteReader();
                    {
                        while (dr.Read())
                        {
                            if (dr[0] != DBNull.Value)
                            {
                                tmpdata = dr[0].ToString();
                            }
                        }
                    }
                    dr.Dispose();
                    cmd.Dispose();
                }
            }
            finally
            {
                //SqlDependency.Stop(connStr);
            }

        }
        #endregion

        #region OnDataChange
        /// <summary>
        /// OnDataChange
        /// OnDataChange will fire when after data change found in ContentChangeLog table
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnDataChange(object sender, SqlNotificationEventArgs e)
        {
            SqlDependency dep = sender as SqlDependency;
            dep.OnChange -= new OnChangeEventHandler(OnDataChange);
            SendMailNotification();
            RegisterNotification();
        }
         #endregion

        #region StartIndex
        /// <summary>
        /// StartIndex
        /// this routine will call web service in bba reman website which will invoke routine to re-index data
        /// </summary>
        void SendMailNotification()
        {
            // does some job

        }
        #endregion

        #region MailNotify
        /// <summary>
        /// MailNotify
        /// fire mail when apps start & exit
        /// </summary>
        /// <param name="strStatus"></param>
        void MailNotify(string strStatus)
        {
            if (strStatus == "STARTED")
            {
                var template = new MailTemplate()
                    .WithBody("HI,<br><br>Part Indexer Started Date " + DateTime.Now.ToLongDateString())
                    .WithSubject("Part Indexer Started")
                    .WithSender("xxxxx")
                    .WithRecepient("xxxx")
                    .Send();
            }
            else if (strStatus == "STOPPED")
            {
                var template = new MailTemplate()
                    .WithBody("HI,<br><br>Part Indexer stopped Date " + DateTime.Now.ToLongDateString())
                    .WithSubject("Part Indexer Stopped")
                    .WithSender("xxx")
                    .WithRecepient("xxx")
                    .Send();
            }
        }
        #endregion

        #region OnStop
        protected override void OnStop()
        {
            System.Data.SqlClient.SqlDependency.Stop(connectionString);
            MailNotify("STOPPED");
        }
        #endregion
    }

tbhattacharjee

Questionwating for anser how to add record to database with gridjanus and bindingnavigator Pin
fatemehsoleimani5-Oct-14 11:53
fatemehsoleimani5-Oct-14 11:53 
AnswerRe: how to add record to database with gridjanus and bindingnavigator Pin
fatemehsoleimani5-Oct-14 20:19
fatemehsoleimani5-Oct-14 20:19 
GeneralRe: how to add record to database with gridjanus and bindingnavigator Pin
fatemehsoleimani5-Oct-14 21:49
fatemehsoleimani5-Oct-14 21:49 
GeneralRe: how to add record to database with gridjanus and bindingnavigator Pin
fatemehsoleimani5-Oct-14 22:50
fatemehsoleimani5-Oct-14 22:50 
GeneralRe: how to add record to database with gridjanus and bindingnavigator Pin
fatemehsoleimani6-Oct-14 3:43
fatemehsoleimani6-Oct-14 3:43 
AnswerRe: wating for anser how to add record to database with gridjanus and bindingnavigator Pin
fatemehsoleimani9-Oct-14 5:30
fatemehsoleimani9-Oct-14 5:30 
Questionif, else if, and else statement. Pin
Member 111309765-Oct-14 9:06
Member 111309765-Oct-14 9:06 
AnswerRe: if, else if, and else statement. Pin
BillWoodruff5-Oct-14 9:56
professionalBillWoodruff5-Oct-14 9:56 
AnswerRe: if, else if, and else statement. Pin
Swinkaran5-Oct-14 12:36
professionalSwinkaran5-Oct-14 12:36 
AnswerRe: if, else if, and else statement. Pin
Dominic Burford8-Oct-14 4:09
professionalDominic Burford8-Oct-14 4:09 
QuestionMessage Removed Pin
5-Oct-14 2:36
fatemehsoleimani5-Oct-14 2:36 
QuestionSystem.NullReferenceException DataGrid WPF Pin
smgetaweh4-Oct-14 6:18
smgetaweh4-Oct-14 6:18 
AnswerRe: System.NullReferenceException DataGrid WPF Pin
Dave Kreskowiak4-Oct-14 7:22
mveDave Kreskowiak4-Oct-14 7:22 
GeneralRe: System.NullReferenceException DataGrid WPF Pin
smgetaweh4-Oct-14 7:40
smgetaweh4-Oct-14 7:40 
GeneralRe: System.NullReferenceException DataGrid WPF Pin
SledgeHammer014-Oct-14 8:57
SledgeHammer014-Oct-14 8:57 
AnswerRe: System.NullReferenceException DataGrid WPF Pin
Praneet Nadkar5-Oct-14 19:58
Praneet Nadkar5-Oct-14 19:58 
GeneralRe: System.NullReferenceException DataGrid WPF Pin
smgetaweh6-Oct-14 4:44
smgetaweh6-Oct-14 4:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.