Showing posts with label message. Show all posts
Showing posts with label message. Show all posts

Friday, March 9, 2012

reusing a single conversation handle

Hi

I have a replicated table that has a trigger attached to the it. The trigger fires off a service broker message for inserts. Originally for every insert, I would begin a conversation, send, and end the conversation when target send an end conversation. Since replication process is only using a single spid, I would like to reuse 1 conversation. the following is what I have for the send procedure in the initiator. I check the conversation_endpoints for any open conversation, if it's null, I start a new conversation and send else just send with the existing conversation. Is there anything wrong with this code? What could cause the conversation on the initiator to be null if I never end the conversation on the initiator side? thanks

DECLARE @.dialog_handle uniqueidentifier

select @.dialog_handle = conversation_handle from sys.conversation_endpoints where state = 'CO'

IF @.dialog_handle is NULL

BEGIN DIALOG CONVERSATION @.dialog_handle

FROM SERVICE [initiator]

TO SERVICE 'target'

ON CONTRACT [portcontract];

SEND ON CONVERSATION @.dialog_handle

MESSAGE TYPE [Port] (@.msg)

Hi

Reusing conversations is generally a good idea and one good way to achieve this is to store a mapping of spid to conversations handle in a lookup table. http://blogs.msdn.com/remusrusanu/archive/2007/05/02/recycling-conversations.aspx goes into the details and helps answer your questions.

Thanks

Ketan

Wednesday, March 7, 2012

Returning the error message in a stored proc

Hi everyone!
I know how to return an error id in a stored proc with the @.@.ERROR
variable but is it possible to also return the corresponding error
message?
Thanks!
Hi
You don't give the version of SQL Server you are using, SQL Server 2005 has
a ERROR_MESSAGE() function. For SQL 2000 you could try looking up the error
message number in master..sysmessages but you won't get the substituted
values.
John
"grosdug@.hotmail.com" wrote:

> Hi everyone!
> I know how to return an error id in a stored proc with the @.@.ERROR
> variable but is it possible to also return the corresponding error
> message?
> Thanks!
>
|||Hi!
SQL 2000 it is, and I tried to get message from sysmessages and I
realised it doesn't substitute the varaibles as you suggest.
So, is there any way to get the message with substitued values?
Thanks!
|||Hi
Not that I know of, although it is available on the client.
John
"grosdug@.hotmail.com" wrote:

> Hi!
> SQL 2000 it is, and I tried to get message from sysmessages and I
> realised it doesn't substitute the varaibles as you suggest.
> So, is there any way to get the message with substitued values?
> Thanks!
>
|||Allright, thanks a lot!

Returning the error message in a stored proc

Hi everyone!
I know how to return an error id in a stored proc with the @.@.ERROR
variable but is it possible to also return the corresponding error
message?
Thanks!Hi!
SQL 2000 it is, and I tried to get message from sysmessages and I
realised it doesn't substitute the varaibles as you suggest.
So, is there any way to get the message with substitued values?
Thanks!|||Allright, thanks a lot!

Returning the error message in a stored proc

Hi everyone!
I know how to return an error id in a stored proc with the @.@.ERROR
variable but is it possible to also return the corresponding error
message?
Thanks!Hi
You don't give the version of SQL Server you are using, SQL Server 2005 has
a ERROR_MESSAGE() function. For SQL 2000 you could try looking up the error
message number in master..sysmessages but you won't get the substituted
values.
John
"grosdug@.hotmail.com" wrote:

> Hi everyone!
> I know how to return an error id in a stored proc with the @.@.ERROR
> variable but is it possible to also return the corresponding error
> message?
> Thanks!
>|||Hi!
SQL 2000 it is, and I tried to get message from sysmessages and I
realised it doesn't substitute the varaibles as you suggest.
So, is there any way to get the message with substitued values?
Thanks!|||Hi
Not that I know of, although it is available on the client.
John
"grosdug@.hotmail.com" wrote:

> Hi!
> SQL 2000 it is, and I tried to get message from sysmessages and I
> realised it doesn't substitute the varaibles as you suggest.
> So, is there any way to get the message with substitued values?
> Thanks!
>|||Allright, thanks a lot!