title: Error connecting to IBM MQ
body: <p>When I execute the code below, I get the following error. Could you tell me why, please? It sounds the problem is with the channel, but I verified and I didn't identified the cause of the problem. I tried many examples from the web, but this problem still remains.</p>
  
  <pre><code>   import java.io.IOException;
  import java.util.Hashtable;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import com.ibm.mq.MQAsyncStatus;
  import com.ibm.mq.MQException;
  import com.ibm.mq.MQMessage;
  import com.ibm.mq.MQPutMessageOptions;
  import com.ibm.mq.MQQueue;
  import com.ibm.mq.MQQueueManager;
  import com.ibm.mq.constants.MQConstants;
  
  public class MQClientTest2 {
  
      private static final Logger LOGGER = LoggerFactory.getLogger(MQClientTest.class);
  
      public static void main(String args[]) {
          // Create a connection to the queue manager
          Hashtable&lt;String, Object&gt; props = new Hashtable&lt;String, Object&gt;();
          props.put(MQConstants.CHANNEL_PROPERTY, "WM.SVRCONN.001");
          props.put(MQConstants.PORT_PROPERTY, 1414);
          props.put(MQConstants.HOST_NAME_PROPERTY, "localhost");
  
          String qManager = "QM1";
          String queueName = "LQ1";
          MQQueueManager qMgr = null;
          try {
              qMgr = new MQQueueManager(qManager, props);
  
              // MQOO_OUTPUT = Open the queue to put messages. The queue is opened for use with subsequent MQPUT calls.
              // MQOO_INPUT_AS_Q_DEF = Open the queue to get messages using the queue-defined default.
              // The queue is opened for use with subsequent MQGET calls. The type of access is either
              // shared or exclusive, depending on the value of the DefInputOpenOption queue attribute.
              int openOptions = MQConstants.MQOO_OUTPUT | MQConstants.MQOO_INPUT_AS_Q_DEF;
  
              // creating destination
              MQQueue queue = qMgr.accessQueue(queueName, openOptions);
  
              // specify the message options...
              MQPutMessageOptions pmo = new MQPutMessageOptions(); // default
              // MQPMO_ASYNC_RESPONSE = The MQPMO_ASYNC_RESPONSE option requests that an MQPUT or MQPUT1 operation
              // is completed without the application waiting for the queue manager to complete the call.
              // Using this option can improve messaging performance, particularly for applications using client bindings.
              pmo.options = MQConstants.MQPMO_ASYNC_RESPONSE;
  
              // create message
              MQMessage message = new MQMessage();
              // MQFMT_STRING = The application message data can be either an SBCS string (single-byte character set),
              // or a DBCS string (double-byte character set). Messages of this format can be converted
              // if the MQGMO_CONVERT option is specified on the MQGET call.
              message.format = MQConstants.MQFMT_STRING;
              message.writeString("&lt;message&gt;Hallo Vinh&lt;/message&gt;");
              queue.put(message, pmo);
              queue.close();
  
              MQAsyncStatus asyncStatus = qMgr.getAsyncStatus();
              System.out.println("valor do asyncStatus: " + asyncStatus.putSuccessCount);
  
          } catch (MQException e) {
              LOGGER.error("Die Verbindung zum Message Broker mit den "
                      + "Eigenschaften {} und dem QueueManager {} konnte nicht hergestellt werden.", props, qManager, e);
          } catch (IOException e) {
              LOGGER.error("Fehler beim Schreiben der Message.", e);
          } finally {
              try {
                  qMgr.disconnect();
              } catch (MQException e) {
                  LOGGER.error("Die Verbindung konnte nicht geschlossen werden.", e);
              }
          }
      }
  }
  </code></pre>
  
  <p>This is the Error that happens when I execute the program:</p>
  
  <pre><code>    23:47:34.255 [main] ERROR com.mkyong.MQClientTest - Die Verbindung zum Message Broker mit den Eigenschaften {hostname=localhost, port=1414, channel=WM.SVRCONN.001} und dem QueueManager QM1 konnte nicht hergestellt werden.
  com.ibm.mq.MQException: MQJE001: Código de Conclusão '2', Razão '2540'.
      at com.ibm.mq.MQManagedConnectionJ11.&lt;init&gt;(MQManagedConnectionJ11.java:255)
      at com.ibm.mq.MQClientManagedConnectionFactoryJ11._createManagedConnection(MQClientManagedConnectionFactoryJ11.java:450)
      at com.ibm.mq.MQClientManagedConnectionFactoryJ11.createManagedConnection(MQClientManagedConnectionFactoryJ11.java:487)
      at com.ibm.mq.StoredManagedConnection.&lt;init&gt;(StoredManagedConnection.java:97)
      at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:194)
      at com.ibm.mq.MQQueueManagerFactory.obtainBaseMQQueueManager(MQQueueManagerFactory.java:874)
      at com.ibm.mq.MQQueueManagerFactory.procure(MQQueueManagerFactory.java:822)
      at com.ibm.mq.MQQueueManagerFactory.constructQueueManager(MQQueueManagerFactory.java:764)
      at com.ibm.mq.MQQueueManagerFactory.createQueueManager(MQQueueManagerFactory.java:200)
      at com.ibm.mq.MQQueueManager.&lt;init&gt;(MQQueueManager.java:979)
      at com.mkyong.MQClientTest2.main(MQClientTest2.java:33)
  Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2540;AMQ9204: Conexão com o host 'localhost(1414)' rejeitada. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2540;AMQ9520: Canal não definido remotamente. [3=WM.SVRCONN.001      ]],3=localhost(1414),5=RemoteConnection.analyseErrorSegment]
      at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:2314)
      at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1285)
      at com.ibm.mq.ese.jmqi.InterceptedJmqiImpl.jmqiConnect(InterceptedJmqiImpl.java:377)
      at com.ibm.mq.ese.jmqi.ESEJMQI.jmqiConnect(ESEJMQI.java:562)
      at com.ibm.mq.MQSESSION.MQCONNX_j(MQSESSION.java:916)
      at com.ibm.mq.MQManagedConnectionJ11.&lt;init&gt;(MQManagedConnectionJ11.java:240)
      ... 10 common frames omitted
  Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2540;AMQ9520: Canal não definido remotamente. [3=WM.SVRCONN.001      ]
      at com.ibm.mq.jmqi.remote.impl.RemoteConnection.analyseErrorSegment(RemoteConnection.java:4464)
      at com.ibm.mq.jmqi.remote.impl.RemoteConnection.receiveTSH(RemoteConnection.java:3199)
      at com.ibm.mq.jmqi.remote.impl.RemoteConnection.initSess(RemoteConnection.java:1274)
      at com.ibm.mq.jmqi.remote.impl.RemoteConnection.connect(RemoteConnection.java:895)
      at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSessionFromNewConnection(RemoteConnectionSpecification.java:416)
      at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSession(RemoteConnectionSpecification.java:312)
      at com.ibm.mq.jmqi.remote.impl.RemoteConnectionPool.getSession(RemoteConnectionPool.java:146)
      at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1761)
      ... 15 common frames omitted
  Exception in thread "main" java.lang.NullPointerException
      at com.mkyong.MQClientTest2.main(MQClientTest2.java:71)
  </code></pre>
  
  <p>Below I put the Image from the place where I configure the channel.</p>
  
  <p><a href="https://i.stack.imgur.com/w5BGi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w5BGi.png" alt="enter image description here"></a></p>
  
  <p>After deleting all queue managers and recreating a new one, I got this new error:</p>
  
  <pre><code>    com.ibm.mq.MQException: MQJE001: Código de Conclusão '2', Razão '2035'.
      at com.ibm.mq.MQManagedConnectionJ11.&lt;init&gt;(MQManagedConnectionJ11.java:255)
      at com.ibm.mq.MQClientManagedConnectionFactoryJ11._createManagedConnection(MQClientManagedConnectionFactoryJ11.java:450)
      at com.ibm.mq.MQClientManagedConnectionFactoryJ11.createManagedConnection(MQClientManagedConnectionFactoryJ11.java:487)
      at com.ibm.mq.StoredManagedConnection.&lt;init&gt;(StoredManagedConnection.java:97)
      at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:194)
      at com.ibm.mq.MQQueueManagerFactory.obtainBaseMQQueueManager(MQQueueManagerFactory.java:874)
      at com.ibm.mq.MQQueueManagerFactory.procure(MQQueueManagerFactory.java:822)
      at com.ibm.mq.MQQueueManagerFactory.constructQueueManager(MQQueueManagerFactory.java:764)
      at com.ibm.mq.MQQueueManagerFactory.createQueueManager(MQQueueManagerFactory.java:200)
      at com.ibm.mq.MQQueueManager.&lt;init&gt;(MQQueueManager.java:979)
      at com.mkyong.MQClientTest2.main(MQClientTest2.java:33)
  Exception in thread "main" java.lang.NullPointerException
      at com.mkyong.MQClientTest2.main(MQClientTest2.java:73)
  </code></pre>
  
  <p>Directory where I installed IBM MQ:</p>
  
  <p><a href="https://i.stack.imgur.com/KR7FF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KR7FF.png" alt="enter image description here"></a></p>
  
  <p>After executing the comand set|findstr MQ: </p>
  
  <pre><code>    Classpath=C:\LINGO64_17\Lingo17.jar;C:\Program Files\IBM\MQ\java\lib\com.ibm.mqjms.jar;C:\Program Files\IBM\MQ\java\lib\com.ibm.mq.jar
  CP=D:\rabbitMQ
  INCLUDE=C:\Program Files\IBM\MQ\tools\c\include;C:\Program Files\IBM\MQ\tools\cplus\include
  LIB=C:\Program Files\IBM\MQ\tools\lib64;C:\Program Files\IBM\MQ\tools\lib
  MQ_FILE_PATH=C:\Program Files\IBM\MQ
  MQ_JAVA_DATA_PATH=C:\ProgramData\IBM\MQ
  MQ_JAVA_INSTALL_PATH=C:\Program Files\IBM\MQ\java
  MQ_JAVA_LIB_PATH=C:\Program Files\IBM\MQ\java\lib64;C:\Program Files\IBM\MQ\java\lib
  MQ_JRE_PATH=C:\Program Files\IBM\MQ\java\jre
  Path=C:\Program Files\IBM\MQ\java\lib;C:\Program Files\IBM\MQ\java\lib64;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\PostgreSQL\pg95\bin;C:\Program Files\Java\jdk1.8.0_131\bin;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Progress\DataDirect\Connect64_for_ODBC_71\drivers;C:\Program Files\Progress\DataDirect\Connect64_for_ODBC_71\jre\bin;C:\Program Files\Progress\DataDirect\Connect64_for_ODBC_71\jre\bin\server;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\LINGO64_17\;C:\Program Files\nodejs\;C:\PostgreSQL\pg96\bin;C:\Program Files\IBM\MQ\bin64;C:\Program Files\IBM\MQ\bin;C:\Program Files\IBM\MQ\tools\c\samples\bin64;C:\Program Files\IBM\MQ\tools\c\samples\bin;C:\Users\camar\AppData\Local\Microsoft\WindowsApps;C:\Users\camar\AppData\Roaming\npm;C:\Program Files\nodejs;
  </code></pre>