1

I will do a project using "sql server service broker". I have never used it but tried tutorials from microsoft website and I think I got the idea. Now, I can create all the required elements for service broker in the database. but my question is, how do you use service broker from c#. I want to add messages to queue from c# and read from c#?

I read that I can access the queue table with old style sql like below

select columns from SchemaName.QueueName WITH(NOLOCK);

but I dont think this is the correct way. how can I do it properly in c#? please give me a clue

dyatchenko
  • 2,283
  • 3
  • 22
  • 32
Arif YILMAZ
  • 5,754
  • 26
  • 104
  • 189

1 Answers1

2

According to BOL, only Service Broker can add to the queue:

Service Broker manages updates to queues. Although the name of a queue can be used in place of a table name in a SELECT statement, a queue cannot be the target of an INSERT, UPDATE, DELETE, or TRUNCATE statement.

You can run normal queries on the queue using ADO .Net

Take a look here: http://msdn.microsoft.com/en-us/library/ms166127%28v=sql.100%29.aspx

Dustin
  • 147
  • 6
  • thats good to know but how do you use it in your project? I can add a message to queue and read a message from queue in sql server managemanet studio with service broker commands. but how do u do it in c# – Arif YILMAZ Jun 20 '13 at 16:43
  • 1
    Try creating a stored procedure in SQL and then call that proc from C#. This link shows how: http://msdn.microsoft.com/en-us/library/59x02y99%28v=vs.100%29.aspx – Dustin Jun 20 '13 at 17:58
  • -1: No. All queue manipulation can be performed with T-SQL extensions from SQL 2005 on. Therefore, any language/API/SDK capable of running commands on SQL can work with Service Broker. There are many examples of this on the web, and even here on SO. E.g.: http://stackoverflow.com/questions/2089184/net-api-for-sql-service-broker – Marc L. Jun 24 '13 at 16:27