Click here to Skip to main content
15,895,011 members
Home / Discussions / C#
   

C#

 
AnswerRe: Sql Dependency onchange event not firing every time c# Pin
Dave Kreskowiak25-Apr-15 10:55
mveDave Kreskowiak25-Apr-15 10:55 
Questionc# opening database to array Pin
ruspj25-Apr-15 8:03
ruspj25-Apr-15 8:03 
AnswerRe: c# opening database to array Pin
Sascha Lefèvre25-Apr-15 8:16
professionalSascha Lefèvre25-Apr-15 8:16 
GeneralRe: c# opening database to array Pin
ruspj25-Apr-15 8:31
ruspj25-Apr-15 8:31 
GeneralRe: c# opening database to array Pin
Sascha Lefèvre25-Apr-15 8:50
professionalSascha Lefèvre25-Apr-15 8:50 
GeneralSharpDevolp 4.3 Pin
Member 465445225-Apr-15 3:41
Member 465445225-Apr-15 3:41 
GeneralRe: SharpDevolp 4.3 Pin
Eddy Vluggen25-Apr-15 7:32
professionalEddy Vluggen25-Apr-15 7:32 
QuestionRegistering SQL Dependency again from onchange event Pin
Tridip Bhattacharjee24-Apr-15 4:48
professionalTridip Bhattacharjee24-Apr-15 4:48 
i like to know is it right approach to registering SQL Dependency again from onchange event ?

one guy review my code and told me registering everything again and again after each notification. As I can recall this will create a queue each time

so i comment this code in onchange event
C#
void OnDataChange(object sender, SqlNotificationEventArgs e)
        {
            BBALogger.Write("PartIndexer Service OnDataChange called start", BBALogger.MsgType.Info);

<pre>
        if (e.Source == SqlNotificationSource.Timeout)
        {
            BBALogger.Write("PartIndexer Service SqlNotificationSource.Timeout error", BBALogger.MsgType.Error);
            Environment.Exit(1);
        }
        else if (e.Source != SqlNotificationSource.Data)
        {
            BBALogger.Write("PartIndexer Service SqlNotificationSource.Data", BBALogger.MsgType.Error);
            Environment.Exit(1);
        }
        else if (e.Type == SqlNotificationType.Change)
        {
            BBALogger.Write("PartIndexer Service Data changed detected", BBALogger.MsgType.Info);
        }
        else
        {
            BBALogger.Write(string.Format("Ignored change notification {0}/{1} ({2})", e.Type, e.Info, e.Source), BBALogger.MsgType.Warnings);
        }

        CallWebService();
        //((SqlDependency)sender).OnChange -= OnDataChange;
        //RegisterNotification();
    }</pre>

just see i comment this line //((SqlDependency)sender).OnChange -= OnDataChange; //RegisterNotification(); but after commenting i found onchange event is firing first time and it is not firing from second time.

guide me with right approach. here is my partial code
C#
void OnDataChange(object sender, SqlNotificationEventArgs e)
{
    BBALogger.Write("PartIndexer Service OnDataChange called start", BBALogger.MsgType.Info);

    if (e.Source == SqlNotificationSource.Timeout)
    {
    BBALogger.Write("PartIndexer Service SqlNotificationSource.Timeout error", BBALogger.MsgType.Error);
    Environment.Exit(1);
    }
    else if (e.Source != SqlNotificationSource.Data)
    {
    BBALogger.Write("PartIndexer Service SqlNotificationSource.Data", BBALogger.MsgType.Error);
    Environment.Exit(1);
    }
    else if (e.Type == SqlNotificationType.Change)
    {
    BBALogger.Write("PartIndexer Service Data changed detected", BBALogger.MsgType.Info);
    }
    else
    {
    BBALogger.Write(string.Format("Ignored change notification {0}/{1} ({2})", e.Type, e.Info, e.Source), BBALogger.MsgType.Warnings);
    }

    CallWebService();
    //((SqlDependency)sender).OnChange -= OnDataChange;
    //RegisterNotification();
}

private void RegisterNotification()
    {
        string tmpdata = "";
        BBALogger.Write("PartIndexer Service RegisterNotification called start", BBALogger.MsgType.Info);

        System.Data.SqlClient.SqlDependency.Stop(connectionString);
        System.Data.SqlClient.SqlDependency.Start(connectionString);

        try
        {
        using (SqlConnection conn = new SqlConnection(connectionString))
        {
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = "SELECT ActivityDate FROM [dbo].tablename";
            dep = new SqlDependency(cmd);
            dep.OnChange += new OnChangeEventHandler(OnDataChange);
            SqlDataReader dr = cmd.ExecuteReader();
            {
            if (dr.HasRows)
            {
                dr.Read();
                tmpdata = dr[0].ToString();
            }
            }
            dr.Dispose();
            cmd.Dispose();
        }
        }
        catch (Exception ex)
        {
        BBALogger.Write("PartIndexer Service RegisterNotification Error "+ex.Message.ToString(), BBALogger.MsgType.Error);
        }
        finally
        {
        BBALogger.Write("PartIndexer Service RegisterNotification called end", BBALogger.MsgType.Info);

        }

}

thanks
tbhattacharjee

QuestionSql Dependency onchange event not firing every time c# Pin
Tridip Bhattacharjee24-Apr-15 3:48
professionalTridip Bhattacharjee24-Apr-15 3:48 
QuestionUnable to connect Oracle database from C# Pin
meeram3924-Apr-15 3:47
professionalmeeram3924-Apr-15 3:47 
AnswerRe: Unable to connect Oracle database from C# Pin
Dave Kreskowiak24-Apr-15 4:03
mveDave Kreskowiak24-Apr-15 4:03 
GeneralRe: Unable to connect Oracle database from C# Pin
meeram3924-Apr-15 14:53
professionalmeeram3924-Apr-15 14:53 
GeneralRe: Unable to connect Oracle database from C# Pin
Dave Kreskowiak24-Apr-15 17:21
mveDave Kreskowiak24-Apr-15 17:21 
GeneralRe: Unable to connect Oracle database from C# Pin
meeram3924-Apr-15 19:28
professionalmeeram3924-Apr-15 19:28 
GeneralRe: Unable to connect Oracle database from C# Pin
meeram3925-Apr-15 0:39
professionalmeeram3925-Apr-15 0:39 
GeneralRe: Unable to connect Oracle database from C# Pin
Dave Kreskowiak25-Apr-15 3:42
mveDave Kreskowiak25-Apr-15 3:42 
GeneralRe: Unable to connect Oracle database from C# Pin
meeram3925-Apr-15 5:46
professionalmeeram3925-Apr-15 5:46 
QuestionHow to Open the Docx File in Silverlight Pin
Hrishikesh Shivacharan24-Apr-15 1:17
Hrishikesh Shivacharan24-Apr-15 1:17 
AnswerRe: How to Open the Docx File in Silverlight Pin
Dave Kreskowiak24-Apr-15 3:37
mveDave Kreskowiak24-Apr-15 3:37 
AnswerRe: How to Open the Docx File in Silverlight Pin
Brisingr Aerowing24-Apr-15 6:31
professionalBrisingr Aerowing24-Apr-15 6:31 
AnswerRe: How to Open the Docx File in Silverlight Pin
Mycroft Holmes24-Apr-15 13:35
professionalMycroft Holmes24-Apr-15 13:35 
GeneralRe: How to Open the Docx File in Silverlight Pin
Hrishikesh Shivacharan6-May-15 21:20
Hrishikesh Shivacharan6-May-15 21:20 
GeneralRe: How to Open the Docx File in Silverlight Pin
Mycroft Holmes6-May-15 22:10
professionalMycroft Holmes6-May-15 22:10 
QuestionAdmin questions about Microsoft exam 70-483 Pin
CRobert45623-Apr-15 4:57
CRobert45623-Apr-15 4:57 
AnswerRe: Admin questions about Microsoft exam 70-483 Pin
Dave Kreskowiak23-Apr-15 9:39
mveDave Kreskowiak23-Apr-15 9:39 

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.