Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
xalpha
Starting Member
13 Posts |
Posted - 2013-04-11 : 08:58:32
|
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.mytableFor 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
5072 Posts |
Posted - 2013-04-11 : 09:19:59
|
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) |
|
|
xalpha
Starting Member
13 Posts |
Posted - 2013-04-20 : 10:02:20
|
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. |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2013-04-22 : 14:25:31
|
Excellent, glad you're working it out. |
|
|
|
|
|