Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connect to remote MQ Server with VB

Status
Not open for further replies.

dtoyer

Programmer
Feb 26, 2003
3
CA
Hi, I am trying to listen for messages on a queue on a remote server through VB. In java, I would set the HostName of the connection factory.
Example:
com.ibm.mq.jms.MQQueueConnectionFactory qcf = new com.ibm.mq.jms.MQQueueConnectionFactory();
qcf.setHostName(ip address);

I can't figure out the equivalent in visual basic using MQI. Can someone help me out or point me in the right direction?

Thanks,
David
 
in our visual basic application, we used the environmental variable -- such as SYSTEM.AUTO.SVRCONN/TCP/IP ADDRESS(1416)

and the used MQSeries Client API calls...

not sure this will help you
 
some additional help

This is a good Quick Reference for setting up MQSeries Clients. It also has some examples of how to test the connection. (It mentions amqscnxc. If you don't have that, you can use amqsputc.)

I don't know about the RC 2063. A similar question was asked here on 10/05/02 and it received no replies. Thread332-375208
 
this is the code that i am using to connect to a queue manager.
Dim gHconn As Long
Dim gHobj As Long

Private Sub Form_Load()
Dim CompCode As Long
Dim Reason As Long

'=========================
'Initialize the structures
'=========================
MQ_SETDEFAULTS

'====================================
'Connect to the default queue manager
'====================================
MQCONN "", gHconn, CompCode, Reason

'========================================================
'If there is a failure, report reason and end application
'========================================================
If CompCode = MQCC_FAILED Then
If Reason = 2059 Then
MsgBox "Cannot connect to queue manager.", vbOKOnly, _
"Reason(2059) MQRC_Q_MGR_NOT_AVAILABLE"
End If
End If
End Sub
you can change according to ur requirment
 
Thanks for everyones comments. I was finally able to get it to work by using the MQCONNX structure. My complete method is as follows:


Private Function OpenListenQueue(ByVal sQueue As String, _
ByVal sQueueManager As String, _
ByVal sHostName As String, _
ByVal lOptions As Long) _
As Boolean

Dim lCompCode As Long ' Completion code
Dim lReason As Long ' lReason code
Dim od As MQOD ' Object descriptor
Dim co As MQCNOCD

sQueueManager = Trim(sQueueManager & "")
sHostName = Trim(sHostName & "")
If sHostName = "" Then sHostName = "127.0.0.1(1414)" 'Localhost on port 1414

If gHconListen = 0 Then
MQCNOCD_DEFAULTS co

co.ConnectOpts.Options = MQCNO_NONE
co.ChannelDef.ChannelName = "SYSTEM.DEF.SVRCONN"
co.ChannelDef.ConnectionName = sHostName

MQCONNXAny sQueueManager, co, gHconListen, lCompCode, lReason
'MQCONN sQueueManager, gHconListen, lCompCode, lReason

If lCompCode = MQCC_FAILED Then
Beep
If lCompCode = 2 And lReason = 2059 Then
SetFormMessage "Error: CompCode = " & lCompCode & "; ReasonCode = " & lReason & vbCrLf & "Queue Manager not available"
Else
SetFormMessage "Error: CompCode = " & lCompCode & "; ReasonCode = " & lReason
End If

OpenListenQueue = False
Exit Function
End If
End If

' Open the queue specified in the Queue textbox if the connect was successful
If gHconListen Then
MQOD_DEFAULTS od

od.ObjectName = sQueue
sQueueManager = Trim(sQueueManager & "")
If sQueueManager <> &quot;&quot; Then od.ObjectQMgrName = sQueueManager

MQOPEN gHconListen, od, lOptions, gHobjListen, lCompCode, lReason

If lCompCode <> MQCC_OK Then
Beep
If lReason = 2085 Then
SetFormMessage &quot;HINT: Check the spelling of the Queue name, which is Case-Sensitive.&quot;
ElseIf lReason = 2087 Then
SetFormMessage &quot;HINT: Check the spelling of the Queue Manager name, which is Case-Sensitive.&quot;
Else
SetFormMessage &quot;Unable to open queue. Reason code: &quot; & lReason
End If
OpenListenQueue = False
Else
OpenListenQueue = True
SetFormMessage &quot;Queue opened successfully&quot;
End If
End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top