?
Solved

Accessing SQL Server Service Broker from unmanaged code.

Posted on 2011-04-28
4
Medium Priority
?
440 Views
Last Modified: 2012-05-11
Hi all,

i am writing an MFC application and have to decide whether to use MSMQ or (prefered) the SQL Server Service Broker for messaging.

Currently i cannot find any information how to access the SQL Server Service Broker from unmanaged C++.

Any information welcome.

Best regards
sahl04
0
Comment
Question by:sahl04
  • 2
4 Comments
 
LVL 9

Expert Comment

by:radcaesar
ID: 35485999
cant u query it using "sys.service_message_types" and use it in ur c++ app?

I dont know that much about c++ libs but here is one from SQL Server

http://msdn.microsoft.com/en-us/library/ms166094.aspx
0
 

Accepted Solution

by:
sahl04 earned 0 total points
ID: 35761937
Found a solution by byself.
From unmanaged C++ (MFC) use OLEDB classes for accessing the database.
Service Broker logic is placed into stored procedures which are simply called from unmanaged C++.
See code below for a short track. (Contains just the pure necessary)

In this simple solution the C++ code just has to generate the message payload and pass it to the stored procedures.


CDataSource serviceBrokerDataSource;
CSession serviceBrokerSession;
CCommand<> callStoredProcedureCommand;
CString connectionString = L"Provider=SQLNCLI10;Server=SomeServer;Database=ServiceBrokerTest;Trusted_Connection=yes;";
serviceBrokerDataSource.OpenFromInitializationString(connectionString);
serviceBrokerSession.Open(serviceBrokerDataSource);
callStoredProcedureCommand.Open(serviceBrokerSession, L"EXEC SendTestMessage");
callStoredProcedureCommand.Close();
serviceBrokerSession.Close();
serviceBrokerDataSource.Close();

Open in new window

0
 

Author Closing Comment

by:sahl04
ID: 35791875
Just one possible solution but not the optimal one i think.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question