SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Notification in C# on table events
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

xalpha
Starting Member

13 Posts

Posted - 04/11/2013 :  08:58:32  Show Profile  Reply with Quote
Hello,

I'm searching for a nice way to get a C# notification if a new row is inserted in a table. The table will be filled by an other closed application and I can't get any information before the item is written to SQL. I only need the ID from the new row.

I already have a running solution. It is possible to use the SqlDependency based on service broker. But for this I have to use a base query like: SELECT [ID] FROM dbo.mytable

For big tables it is not a proper solution...

Maybe I can use an insert trigger and update a status table that only holds one row with the newest ID. But I think there must be a better solution?

Where are the SQL/C# professionals? Has someone the way of best practice?

russell
Pyro-ma-ni-yak

USA
5071 Posts

Posted - 04/11/2013 :  09:19:59  Show Profile  Visit russell's Homepage  Reply with Quote
Without knowing your exact requirements, I'd have to say that this type of thing is exactly what service broker is for -- sending asynchronous messages to other applications.

Is ID an identity column? Can use scope_identity() to retrieve the new ID inserted, or @@identity to retrieve the last ID inserted (by any session)
Go to Top of Page

xalpha
Starting Member

13 Posts

Posted - 04/20/2013 :  10:02:20  Show Profile  Reply with Quote
I have to thank you for this hint!

In fact the service broker was exactly what I need. It took a bit time to get familiar with that concept but it was the right way.

Thank you.
Go to Top of Page

russell
Pyro-ma-ni-yak

USA
5071 Posts

Posted - 04/22/2013 :  14:25:31  Show Profile  Visit russell's Homepage  Reply with Quote
Excellent, glad you're working it out.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000