|   | 
	 
  
    | 
RSS Feed - WebSphere MQ Support
 | 
RSS Feed - Message Broker Support
 |   
 
  
	     | 
	 | 
   
 
  
	|  Error connection to QManager using vb.net | 
	« View previous topic :: View next topic »  | 
   
  
  	
	  
		
		
		  | Author | 
		  Message
		 |  
		
		  | ekoks | 
		  
		    
			  
				 Posted: Mon Feb 22, 2016 5:28 am    Post subject: Error connection to QManager using vb.net | 
				     | 
			   
			 
		   | 
		 
		
		   Newbie
 
 Joined: 22 Feb 2016 Posts: 5
  
  | 
		  
		    
			  
				Hello,
 
 
I'm writing a VB.Net program tom monitor the queue depth of several queues. On my development machine, my code is working. Here I've installed MQ Client. 
 
However on another machine, where the program will be running finally, I'm getting an error when connection to the MQ Manager.
 
 
I've copied the amqmdnet.dll and the amqmdxcs.dll to the target machine 
 
and registered them in the GAC using gacutil.
 
 
I don't want to install the MQ Client on the target machine.
 
 
This is my error:
 
Unhandled Exception: System.TypeInitializationException: The type initializer for 'IBM.WMQ.Nmqi.UnmanagedNmqiMQ' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
 
   at IBM.WMQ.Nmqi.NativeManager.InitializeNativeApis(String mode)
 
   at IBM.WMQ.Nmqi.UnmanagedNmqiMQ..cctor()
 
   --- End of inner exception stack trace ---
 
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
 
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
 
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
 
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
 
   at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
 
   at IBM.WMQ.Nmqi.NmqiEnvironment.GetInstance(String name)
 
   at IBM.WMQ.Nmqi.NmqiEnvironment.GetMQI(Int32 id)
 
   at IBM.WMQ.MQQueueManager.Connect(String queueManagerName)
 
   at IBM.WMQ.MQQueueManager..ctor(String queueManagerName, String Channel, String ConnName)
 
   at MQQueueDepth.main.Main() 
 
 
This is my simplified code:
 
 
   
	| Code: | 
   
  
	
 
Imports IBM.WMQ
 
 
Module main
 
 
    Sub Main()
 
        Dim QueueName As String
 
        Dim QueueManagerNAme As String
 
        Dim ChannelInfo As String
 
        Dim ConnectionName As String
 
 
        Dim queuemanager As MQQueueManager
 
        Dim queue As MQQueue
 
 
        Dim intQueueDepth As Integer
 
 
        QueueName = "SomeQueue"
 
 
        QueueManagerNAme = "QMName"
 
        ChannelInfo = "SYSTEM.ADMIN.SVRCONN"
 
        ConnectionName = "hostname(portnumber)"
 
 
        Try
 
            queuemanager = New MQQueueManager(QueueManagerNAme, ChannelInfo, ConnectionName)
 
 
            ' queue = queuemanager.AccessQueue(QueueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INQUIRE)
 
 
            queue = queuemanager.AccessQueue(QueueName, MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INQUIRE)
 
            intQueueDepth = queue.CurrentDepth
 
            MsgBox("Queuedepth for queue " & QueueName & " : " & intQueueDepth.ToString)
 
            queue.Close()
 
            queuemanager.Disconnect()
 
        Catch e As MQException
 
            MsgBox("Exception Occurred: " & vbCrLf & e.Message)
 
        End Try
 
    End Sub
 
 
End Module
 
 | 
   
 
 
 
As I mentioned before, this code is working on my development PC.
 
 
Does anybody know what my I'm doing wrong ?
 
 
best regards,
 
Eduard Koks
  Last edited by ekoks on Tue Feb 23, 2016 1:24 am; edited 1 time in total | 
			   
			 
		   | 
		 
		
		  | Back to top | 
		  
		  	
		   | 
		 
		
		    | 
		 
		
		  | fjb_saper | 
		  
		    
			  
				 Posted: Mon Feb 22, 2016 5:31 am    Post subject:  | 
				     | 
			   
			 
		   | 
		 
		
		    Grand High Poobah
 
 Joined: 18 Nov 2003 Posts: 20768 Location: LI,NY 
  | 
		  
		    
			  
				Yes. Look up the infocenter on how to create a MANAGED connection.
 
To use an Unmanaged connection, like you're doing, you need the MQ Client.
 
 
Have fun   _________________ MQ & Broker admin | 
			   
			 
		   | 
		 
		
		  | Back to top | 
		  
		  	
		   | 
		 
		
		    | 
		 
		
		  | PeterPotkay | 
		  
		    
			  
				 Posted: Mon Feb 22, 2016 3:47 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		 
		
		    Poobah
 
 Joined: 15 May 2001 Posts: 7723
  
  | 
		  
		    
		   | 
		 
		
		  | Back to top | 
		  
		  	
		   | 
		 
		
		    | 
		 
		
		  | ekoks | 
		  
		    
			  
				 Posted: Tue Feb 23, 2016 1:22 am    Post subject:  | 
				     | 
			   
			 
		   | 
		 
		
		   Newbie
 
 Joined: 22 Feb 2016 Posts: 5
  
  | 
		  
		    
			  
				Solved my problem. As stated by fjb_saper, when MQ Client is not installed, I had to create a managed connection.
 
 
Here is my new code:
 
 
   
	| Code: | 
   
  
	
 
Module main
 
 
    Sub Main()
 
        Dim QueueName As String
 
        Dim QueueManagerName As String
 
 
        Static MQproperties As Hashtable = New Hashtable
 
 
        Dim queuemanager As MQQueueManager
 
        Dim queue As MQQueue
 
 
        Dim intQueueDepth As Integer
 
 
        QueueName = "SomeQueue"
 
 
        QueueManagerName = "QMName" ' Name of the QManager
 
 
        ' Setup the MQ Environment
 
        MQEnvironment.Hostname = "myHost" ' IP Address or name of the host to connect to
 
        MQEnvironment.Port = "99999" ' Portnumber 
 
        MQEnvironment.Channel = "SYSTEM.ADMIN.SVRCONN" ' Channel name
 
 
        ' Be sure to create a managed connection, necessary when MQ Client is not installed
 
        MQproperties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED)
 
 
        Try
 
            queuemanager = New MQQueueManager(QueueManagerName, properties)
 
            queue = queuemanager.AccessQueue(QueueName, MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INQUIRE)
 
            intQueueDepth = queue.CurrentDepth
 
            MsgBox("Queuedepth for queue " & QueueName & " : " & intQueueDepth.ToString)
 
            queue.Close()
 
            queuemanager.Disconnect()
 
        Catch e As MQException
 
            MsgBox("Exception Occurred: " & vbCrLf & e.Message)
 
        End Try
 
 
    End Sub
 
End Module
 
 
 | 
   
 
 
 
Thanks for your cooperation. | 
			   
			 
		   | 
		 
		
		  | Back to top | 
		  
		  	
		   | 
		 
		
		    | 
		 
		
		  | 
		    
		   | 
		 
	   
	 | 
   
 
  
	     | 
	 | 
	Page 1 of 1 | 
   
 
 
 
  
  	
	  
		
		  
 
  | 
		  You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
  | 
  		 
	   
	 | 
   
 
  	 | 
	  |