Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7488547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:56:52+00:00 2026-05-29T14:56:52+00:00

I’m having some issues integrating the SqlDependency service with my Windows Forms App, and

  • 0

I’m having some issues integrating the SqlDependency service with my Windows Forms App, and I was hoping someone could help a rookie out. I just want to preface this with that, I know my database connection string and my query statements are correct. Additionally, I know that the service broker is enabled on my database. Issuing:

SELECT is_broker_enabled FROM sys.databases WHERE name = 'Database'

Returns a 1 from the query.

I start the dependency in my main forms loading event, like so:

SqlDependency::Stop(Get_DB_String());
SqlDependency::Start(Get_DB_String());

Then I pull from my database as follows:

    bindingSource->DataSource = GetData("Select * From Table", 
                                              Get_DB_String(), 
                                                 dataAdapter);
    dataGridView->DataSource = bindingSource;

Where GetData is defined as:

DataTable^ GetData( String^ sqlCommand, String^ connectionString, SqlDataAdapter^ adapter )
   {
      SqlConnection^ Connection = gcnew SqlConnection(connectionString);
      SqlCommand^ command = gcnew SqlCommand(sqlCommand,Connection);
      command->Notification = nullptr;              
      SqlDependency^ dependency = gcnew SqlDependency(command);     
      dependency->OnChange += gcnew OnChangeEventHandler(this, &LabSchedule::Form1::OnChange);
      adapter->SelectCommand = command;
      DataTable^ table = gcnew DataTable;
      adapter->Fill(table);  
      return table;
   }

And my change handler is defined as follows:

System::Void OnChange(System::Object^ sender, SqlNotificationEventArgs^ e)
{

    ISynchronizeInvoke^ i = (ISynchronizeInvoke^)this;

    if (i->InvokeRequired)
    {

        OnChangeEventHandler^ tempDelegate =
            gcnew OnChangeEventHandler(this, &LabSchedule::Form1::OnChange);

        array<System::Object^>^ args = { sender, e };

        i->BeginInvoke(tempDelegate, args);

        return;
    }

    SqlDependency^ dependency = (SqlDependency^)sender;
    dependency->OnChange -= gcnew OnChangeEventHandler(this, &LabSchedule::Form1::OnChange);

    if(dependency->HasChanges)
    {
        // This is where I check the properties of the notification  
        MessageBox::Show(e->Info.ToString() + "\n" + e->Source.ToString() + "\n" + e->Type.ToString());
    }

}

When I change something in my database from my local client, it fires the change event and all seems well. However, when I initiate a change from a client on another machine, the OnChange event never gets fired. I’m assuming I’m doing something wacky, but I don’t have the insight to figure it out. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T14:56:55+00:00Added an answer on May 29, 2026 at 2:56 pm

    After seemingly an endless amount of research, the problem I was having was rooted in the design of my table and not my code. Here were the three things that I presumably changed to remedy the problem:

    The statement must not reference the large object types: text, ntext, and image.

    I was using “ntext” as the data type of one of my columns.

    The statement may not use the asterisk (*) or table_name.* syntax to specify columns.

    Initially, I was using the wildcard to select data from my table.

    The projected columns in the SELECT statement must be explicitly stated, and table names must be qualified with two-part names.

    I wasn’t using two-part table names in my SELECT statements, i.e., “Table_name” instead of “dbo.Table_name”.

    This one was a hard one to peg down, and I hope this helps anyone else having similar issues. I misspoke in my initial description of my problem, because my queries, though perfectly legal, were invalid for SqlNotifications.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.