Missing conversation handle in Service Broker












0














I'm creating a conversation for my queue on Service Broker (SQL 2016) using the following :



BEGIN TRANSACTION

BEGIN DIALOG CONVERSATION @NotificationDialog
FROM SERVICE ChangeNotifications
TO SERVICE 'ChangeNotifications'
ON CONTRACT [http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]
WITH ENCRYPTION = OFF;

-- Send the message
--
SEND ON CONVERSATION @NotificationDialog
MESSAGE TYPE [http://schemas.microsoft.com/SQL/Notifications/QueryNotification] (@Message)

COMMIT TRANSACTION


I'm receiving the message in a windows service using the following code:



using (SqlCommand cmd = new SqlCommand("WAITFOR ( RECEIVE * FROM dbo.NotificationsQueue);", cnn))
{
cmd.CommandTimeout = 0;
cnn.Open();

// Execute the command - we will wait here until a new entry appears in the Notification Queue
//
SqlDataReader reader = cmd.ExecuteReader();

// Get the message text from the reader
//
while (reader.Read())
{
// Get the message body text and convert into a legible format
//
messageText = reader.GetString(reader.GetOrdinal("message_body"));
messtype = reader.GetString(reader.GetOrdinal("message_type_name"));
convhandle = reader.GetGuid(reader.GetOrdinal("conversation_handle"));
}

reader.Close();
reader = null;

if (messtype == @"http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog" ||
messtype == @"http://schemas.microsoft.com/SQL/ServiceBroker/Error" ||
messtype == @"http://schemas.microsoft.com/SQL/Notifications/QueryNotification" )
{
var cmd2 = new SqlCommand("end conversation '" + convhandle.ToString() + "'", cnn);

cmd2.ExecuteNonQuery();

cmd2.Dispose();
}
}


When the code tries to execute the end conversation, I get an error 'The conversation handle is not found.'. If I search sys.conversation_endpoints for the handle it doesn't exist either. I'm not actively ending the conversation anywhere.
Why is there no record for it?










share|improve this question






















  • Are you running a Stored Procedure? The use following : cmd2.CommandType = System.Data.CommandType.StoredProcedure;
    – jdweng
    Dec 28 '18 at 11:21










  • @jdweng, the code is clearly not executing a stored procedure.
    – Dan Guzman
    Dec 28 '18 at 11:53










  • I don't see anything obvious in the code you posted that would case this error, although I recommend parameterizing the END CONVERSATION query and surrounding in a using block like the outer query.
    – Dan Guzman
    Dec 28 '18 at 12:05
















0














I'm creating a conversation for my queue on Service Broker (SQL 2016) using the following :



BEGIN TRANSACTION

BEGIN DIALOG CONVERSATION @NotificationDialog
FROM SERVICE ChangeNotifications
TO SERVICE 'ChangeNotifications'
ON CONTRACT [http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]
WITH ENCRYPTION = OFF;

-- Send the message
--
SEND ON CONVERSATION @NotificationDialog
MESSAGE TYPE [http://schemas.microsoft.com/SQL/Notifications/QueryNotification] (@Message)

COMMIT TRANSACTION


I'm receiving the message in a windows service using the following code:



using (SqlCommand cmd = new SqlCommand("WAITFOR ( RECEIVE * FROM dbo.NotificationsQueue);", cnn))
{
cmd.CommandTimeout = 0;
cnn.Open();

// Execute the command - we will wait here until a new entry appears in the Notification Queue
//
SqlDataReader reader = cmd.ExecuteReader();

// Get the message text from the reader
//
while (reader.Read())
{
// Get the message body text and convert into a legible format
//
messageText = reader.GetString(reader.GetOrdinal("message_body"));
messtype = reader.GetString(reader.GetOrdinal("message_type_name"));
convhandle = reader.GetGuid(reader.GetOrdinal("conversation_handle"));
}

reader.Close();
reader = null;

if (messtype == @"http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog" ||
messtype == @"http://schemas.microsoft.com/SQL/ServiceBroker/Error" ||
messtype == @"http://schemas.microsoft.com/SQL/Notifications/QueryNotification" )
{
var cmd2 = new SqlCommand("end conversation '" + convhandle.ToString() + "'", cnn);

cmd2.ExecuteNonQuery();

cmd2.Dispose();
}
}


When the code tries to execute the end conversation, I get an error 'The conversation handle is not found.'. If I search sys.conversation_endpoints for the handle it doesn't exist either. I'm not actively ending the conversation anywhere.
Why is there no record for it?










share|improve this question






















  • Are you running a Stored Procedure? The use following : cmd2.CommandType = System.Data.CommandType.StoredProcedure;
    – jdweng
    Dec 28 '18 at 11:21










  • @jdweng, the code is clearly not executing a stored procedure.
    – Dan Guzman
    Dec 28 '18 at 11:53










  • I don't see anything obvious in the code you posted that would case this error, although I recommend parameterizing the END CONVERSATION query and surrounding in a using block like the outer query.
    – Dan Guzman
    Dec 28 '18 at 12:05














0












0








0







I'm creating a conversation for my queue on Service Broker (SQL 2016) using the following :



BEGIN TRANSACTION

BEGIN DIALOG CONVERSATION @NotificationDialog
FROM SERVICE ChangeNotifications
TO SERVICE 'ChangeNotifications'
ON CONTRACT [http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]
WITH ENCRYPTION = OFF;

-- Send the message
--
SEND ON CONVERSATION @NotificationDialog
MESSAGE TYPE [http://schemas.microsoft.com/SQL/Notifications/QueryNotification] (@Message)

COMMIT TRANSACTION


I'm receiving the message in a windows service using the following code:



using (SqlCommand cmd = new SqlCommand("WAITFOR ( RECEIVE * FROM dbo.NotificationsQueue);", cnn))
{
cmd.CommandTimeout = 0;
cnn.Open();

// Execute the command - we will wait here until a new entry appears in the Notification Queue
//
SqlDataReader reader = cmd.ExecuteReader();

// Get the message text from the reader
//
while (reader.Read())
{
// Get the message body text and convert into a legible format
//
messageText = reader.GetString(reader.GetOrdinal("message_body"));
messtype = reader.GetString(reader.GetOrdinal("message_type_name"));
convhandle = reader.GetGuid(reader.GetOrdinal("conversation_handle"));
}

reader.Close();
reader = null;

if (messtype == @"http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog" ||
messtype == @"http://schemas.microsoft.com/SQL/ServiceBroker/Error" ||
messtype == @"http://schemas.microsoft.com/SQL/Notifications/QueryNotification" )
{
var cmd2 = new SqlCommand("end conversation '" + convhandle.ToString() + "'", cnn);

cmd2.ExecuteNonQuery();

cmd2.Dispose();
}
}


When the code tries to execute the end conversation, I get an error 'The conversation handle is not found.'. If I search sys.conversation_endpoints for the handle it doesn't exist either. I'm not actively ending the conversation anywhere.
Why is there no record for it?










share|improve this question













I'm creating a conversation for my queue on Service Broker (SQL 2016) using the following :



BEGIN TRANSACTION

BEGIN DIALOG CONVERSATION @NotificationDialog
FROM SERVICE ChangeNotifications
TO SERVICE 'ChangeNotifications'
ON CONTRACT [http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]
WITH ENCRYPTION = OFF;

-- Send the message
--
SEND ON CONVERSATION @NotificationDialog
MESSAGE TYPE [http://schemas.microsoft.com/SQL/Notifications/QueryNotification] (@Message)

COMMIT TRANSACTION


I'm receiving the message in a windows service using the following code:



using (SqlCommand cmd = new SqlCommand("WAITFOR ( RECEIVE * FROM dbo.NotificationsQueue);", cnn))
{
cmd.CommandTimeout = 0;
cnn.Open();

// Execute the command - we will wait here until a new entry appears in the Notification Queue
//
SqlDataReader reader = cmd.ExecuteReader();

// Get the message text from the reader
//
while (reader.Read())
{
// Get the message body text and convert into a legible format
//
messageText = reader.GetString(reader.GetOrdinal("message_body"));
messtype = reader.GetString(reader.GetOrdinal("message_type_name"));
convhandle = reader.GetGuid(reader.GetOrdinal("conversation_handle"));
}

reader.Close();
reader = null;

if (messtype == @"http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog" ||
messtype == @"http://schemas.microsoft.com/SQL/ServiceBroker/Error" ||
messtype == @"http://schemas.microsoft.com/SQL/Notifications/QueryNotification" )
{
var cmd2 = new SqlCommand("end conversation '" + convhandle.ToString() + "'", cnn);

cmd2.ExecuteNonQuery();

cmd2.Dispose();
}
}


When the code tries to execute the end conversation, I get an error 'The conversation handle is not found.'. If I search sys.conversation_endpoints for the handle it doesn't exist either. I'm not actively ending the conversation anywhere.
Why is there no record for it?







c# sql-server-2016 service-broker






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 28 '18 at 11:14









Rob MarshRob Marsh

207313




207313












  • Are you running a Stored Procedure? The use following : cmd2.CommandType = System.Data.CommandType.StoredProcedure;
    – jdweng
    Dec 28 '18 at 11:21










  • @jdweng, the code is clearly not executing a stored procedure.
    – Dan Guzman
    Dec 28 '18 at 11:53










  • I don't see anything obvious in the code you posted that would case this error, although I recommend parameterizing the END CONVERSATION query and surrounding in a using block like the outer query.
    – Dan Guzman
    Dec 28 '18 at 12:05


















  • Are you running a Stored Procedure? The use following : cmd2.CommandType = System.Data.CommandType.StoredProcedure;
    – jdweng
    Dec 28 '18 at 11:21










  • @jdweng, the code is clearly not executing a stored procedure.
    – Dan Guzman
    Dec 28 '18 at 11:53










  • I don't see anything obvious in the code you posted that would case this error, although I recommend parameterizing the END CONVERSATION query and surrounding in a using block like the outer query.
    – Dan Guzman
    Dec 28 '18 at 12:05
















Are you running a Stored Procedure? The use following : cmd2.CommandType = System.Data.CommandType.StoredProcedure;
– jdweng
Dec 28 '18 at 11:21




Are you running a Stored Procedure? The use following : cmd2.CommandType = System.Data.CommandType.StoredProcedure;
– jdweng
Dec 28 '18 at 11:21












@jdweng, the code is clearly not executing a stored procedure.
– Dan Guzman
Dec 28 '18 at 11:53




@jdweng, the code is clearly not executing a stored procedure.
– Dan Guzman
Dec 28 '18 at 11:53












I don't see anything obvious in the code you posted that would case this error, although I recommend parameterizing the END CONVERSATION query and surrounding in a using block like the outer query.
– Dan Guzman
Dec 28 '18 at 12:05




I don't see anything obvious in the code you posted that would case this error, although I recommend parameterizing the END CONVERSATION query and surrounding in a using block like the outer query.
– Dan Guzman
Dec 28 '18 at 12:05












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957638%2fmissing-conversation-handle-in-service-broker%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957638%2fmissing-conversation-handle-in-service-broker%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas