Link to home
Start Free TrialLog in
Avatar of ashishn90
ashishn90

asked on

MSMQ Error

I have a network where MSMQ PEC is installed on NT Server.I run a service on server where i create a queue on another machine which is independent client.
im able to create the queue but while opening it gives me access denied .
any body help pls??
ashish
Avatar of Arvindtn
Arvindtn

It would be more helpful if you show the part of the code used to open the queue.
Avatar of ashishn90

ASKER

The code is
try
{
m_pQueueInfo->Create();
}
catch (_com_error& e)
{
 if (e.Error() == MQ_ERROR_QUEUE_EXISTS)
{}
else if(e.Error() == MQ_ERROR_ACCESS_DENIED)
{
FILE *fp = fopen("C:\\Click-Logs\\MSMQ.txt","a+");
fprintf(fp,"MQ_ERROR_ACCESS_DENIED  Error\n");
close(fp);
CoUninitialize();
}
try
{
m_pQueue = m_pQueueInfo->Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE);
}
catch (_com_error& e)
{
if(e.Error() == MQ_ERROR_ACCESS_DENIED)
{
FILE *fp = fopen("C:\\Click-Logs\\MSMQ.txt","a+");
fprintf(fp,"MQ_ERROR_ACCESS_DENIED  Error");
fclose(fp);
}
else
{
FILE *fp = fopen("C:\\Click-Logs\\MSMQ.txt","a+");
fprintf(fp,"Cannot open the queue");
fclose(fp);
}

CoUninitialize();
return FALSE;
}

I get a error in Open catch block.This code is presnt in a service which runs on NT Server which is PEC for MSMQ.Queue is created on another machine on network which is independent client.It does not allow to open
Ashish  
m_pQueue = m_pQueueInfo->Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE);

The II parameter u used to open the queue is wrong, It should be MQ_DENY_RECEIVE_SHARE

I have explained the parameter taken by MQOpenQueue() and their implications for a better undesrtanding. MQOpenQueue() is a C-API provided by MSMQ.

MQOpenQueue() Takes four parameter.

I Parameter - FormatName - Got using MQCreateQueue() / MQPathNameToFormatName()

II Parameter - dwAccess - The Possible values it can take is.

MQ_PEEK_ACCESS - Message can be looked at, they cannot be removed from the queue.

MQ_SEND_ACCESS - Message can be sent to the Queue, The messages on the queue cannot be looked at or removed.

MQ_RECEIVE_ACCESS - Message can be looked at or removed from the queue.

III Parameter - ShareMode - The Value it takes depends on the II Parameter. The possible values are.

MQ_DENY_NONE - Other program may open the Queue while this one has it open. This required in case of
dwAccess = MQ_PEEK_ACCESS or
           MQ_SEND_ACCESS

MQ_DENY_RECEIVE_SHARE - Only this program can receive messages from the queue. If another process has the queue open for MQ_RECEIVE_ACCESS, whether it is shared or not, the program will not able to open the queue.

Syntax to open the queue to receive message should be

MQOpenQueue(wcFormatName,
            MQ_RECEIVE_ACCESS,
            MQ_DENY_RECEIVE_SHARE,
            &hQueue );
If u still have problems message me
ASKER CERTIFIED SOLUTION
Avatar of Arvindtn
Arvindtn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial