Accessing SQL Server Service Broker from unmanaged code.

Posted on 2011-04-28
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
Question by:sahl04
    LVL 9

    Expert Comment

    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
    LVL 12

    Expert Comment


    Accepted Solution

    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;";
    callStoredProcedureCommand.Open(serviceBrokerSession, L"EXEC SendTestMessage");

    Open in new window


    Author Closing Comment

    Just one possible solution but not the optimal one i think.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    SQL User Mappings error 3 32
    SQL Server 2008 9 30
    SQL Select Query problems 10 37
    Alter table to increase max Len 6 11
    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…
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    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.

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now