I am unable to connect to IBM MQ from C# console application with credentials. Here is the code. Its throwing "2035 Not Authorized" error.
protected MQQueueManager mqQueueManager;
public override void Open() {
Hashtable properties = new Hashtable();
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
properties.Add(MQC.HOST_NAME_PROPERTY, mq_hostName);
properties.Add(MQC.CHANNEL_PROPERTY, mq_channel);
properties.Add(MQC.PORT_PROPERTY, mq_port);
properties.Add(MQC.USER_ID_PROPERTY, mq_userName);
properties.Add(MQC.PASSWORD_PROPERTY, mq_password);
properties.Add(MQC.USE_MQCSP_AUTHENTICATION_PROPERTY, true);
try
{
mqQueueManager = new MQQueueManager(mq_queueManagerName, properties);
Console.WriteLine("Connected to MQ");
}
catch (MQException e)
{
log.Fatal("MQ Queue Manager creation Error", e);
throw e;
}
}
What I have tried:
If I comment user name and password properties. It’s able to connect. Not sure, why it’s not working with credentials. Please let me know if anyone has encountered this issue and any pointers to resolve the same.
Its an issue with user name. We are migrating Java application to .NET and in user name "#domain" was there at the end. Looks like, this format is required for Java and its working fine there. When we use same user name in .NET, it was not working and throwing error "2035 MQRC_NOT_AUTHORIZED". Once we removed #domain from it, it started working.
Related
Below Code is just working fine with IBMMQ 8.0 DLL and server when I switch to 7.5 (both DLL and server) it is giving me this error using same certificate
The SSL key repository cannot be used because MQ cannot obtain a
password to access it. Reasons giving rise to this error include: &B
(a) the key database file and password stash file are not present in
the location configured for the key repository, &B (b) the key
database file exists in the correct place but that no password stash
file has been created for it, &B (c) the files are present in the
correct place but the userid under
public void test() {
Environment.SetEnvironmentVariable("MQCCSID", "437");
MQQueueManager mQQueueManager = null;
MQQueue mQQueue = null;
Hashtable hashTable = null;
try {
hashTable = new Hashtable();
// Setup properties for connection
hashTable.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
hashTable.Add(MQC.HOST_NAME_PROPERTY, "IP");
hashTable.Add(MQC.PORT_PROPERTY, 1414);
hashTable.Add(MQC.CHANNEL_PROPERTY, "Channel");
hashTable.Add(MQC.PASSWORD_PROPERTY, "123");
hashTable.Add(MQC.USER_ID_PROPERTY, "user");
mQQueueManager = new MQQueueManager("QueueName", hashTable);
// Open queue for browsing
mQQueue = mQQueueManager.AccessQueue("que", MQC.MQOO_BROWSE | MQC.MQOO_FAIL_IF_QUIESCING);
ListOfMessages = new List < MQMessageDto > ();
// In a loop browse all messages till we reach end of queue
while (true) {
try {
// Need to create objects everytime
var mQMessage = new MQMessage();
var mQGetMessageOptions = new MQGetMessageOptions {
// Use browse next option to start browsing
Options = MQC.MQGMO_BROWSE_NEXT
};
mQQueue.Get(mQMessage, mQGetMessageOptions);
ListOfMessages.Add(new MQMessageDto() {
Id = ListOfMessages.Count + 1,
Message = Encoding.UTF8.GetString(mQMessage.ReadBytes(mQMessage.MessageLength))
});
} catch (MQException mqex) {
if (ListOfMessages.Count == 0) {
MessageBox.Show("There is no messages in MQ");
}
mQQueue.Close();
break;
}
}
mQQueueManager.Disconnect();
grdMessages.DataSource = ListOfMessages;
grdMessages.Columns["Id"].Width = (int)(grdMessages.Width * 0.1);
grdMessages.Columns["Message"].Width = (int)(grdMessages.Width * 0.8);
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
What are you describing means you have wrong configuration at IBM side, and Since you are using IBM MQ 7.5. I think you got the path for the SSL key repository wrong, it should point to the key name not the folder.
Also make sure that you have selected Optional from SSL tab inside your Channel.
For more details.. More details about this issue can be found here about error this error code:
2538 error on MQ for SSL channel connection
You didn't mention which specific level of 7.5 you are using. If it is 7.5.0.7 or earlier, the stash file will likely be the problem:
https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.1.0/com.ibm.mq.mig.doc/q128820_.htm
Older versions of the cryptographic provider used by MQ (GSKit) use a different stash file format for the keystore password.
While newer GSKit versions can handle the old stash file format, the new format is not readable by older GSKit versions. If you are using a level which uses the new format, you can create a backwards-compatible stash file with the -v1stash option:
runmqakm -keydb -stashpw -db <filename> -pw <password> -v1stash
A better alternative, as MQ 7.5 is out of support, would be to use a newer client level, which can still communicate with a 7.5 queue manager if required.
For reference, the first GSKit level which uses the new stash file format is 8.0.50.69. Levels of GSKit bundled with MQ are listed here: https://www.ibm.com/support/pages/levels-jre-and-gskit-bundled-ibm-mq
Regarding:
When I upgraded my client to V9 I'm getting "MQRC_Q_MGR_NOT_AVAILABLE" on client and "4/23/2020 21:03:22 - Process(11764.64) User() Program(amqrmppa.exe) Host(HOST) Installation(Installation1) VRMF(7.5.0.2) QMgr() Remote channel '' did not specify a CipherSpec. Remote channel '' did not specify a CipherSpec when the local channel expected one to be specified. &P The remote host is '...* (...)'. &P The channel did not start. Change the remote channel '' on host ()' to specify a CipherSpec so that both ends of the channel have matching CipherSpecs." in server
display the cipher spec being used dis chl(xxx) SSLCIPH
You may have specified something which is no longer supported by the underlying TLS support.
dis chl(xxx)
I am trying to automatically create an SSH connection for a program that uses an SSH tunnel to update a local database from a remote PostgreSQL server. Up to this time, I have been manually opening a tunnel with PuTTY (including local port forwarding instructions with the -L command). I want to use ssh.net to automatically open the port when the program is run. Once the connection is made, the program uses Entity Framework Core to access the remote database.
When I open the SSH connection with PuTTY, the program runs fine. This is the PuTTY command:
//plink.exe -i "C:\Users\user.name\Desktop\host_private_key.ppk" -L 6544:111.22.33.66:6543 -N user#address.io -pw *PASSWORD*"
(login details removed for privacy)
This is the ssh.net code that I have trying to open the same connection:
public void MakeSSHTunnel()
{
string password = "password";
// path of RSA private key in openSSH format:
string privateKeyPath = "C:/Users/user.name/.ssh/id_rsa";
try
{
// creates variable to transmit RSA private key + passphrase to server via SSH.NET, openSSH compatible.
var privateKeyFile = new PrivateKeyFile(privateKeyPath, password);
string serverAddress = "address.io";
string user = "user";
// allows for the remote port forwarding options required by the server
using (var client = new SshClient(serverAddress, user, privateKeyFile))
{
client.Connect();
var tunnel = new ForwardedPortLocal(6544, "111.22.33.66", 6543);
client.AddForwardedPort(tunnel);
// testing weather the connection has been successful:
if (client.IsConnected)
{
Console.WriteLine("OPENTUNNEL.CS: Connection to {0} successful.", serverAddress);
state = "Open";
}
else
{
Console.WriteLine("Connection to {0} failed.");
state = "Closed";
}
tunnel.Exception += delegate (object sender, ExceptionEventArgs e)
{
Console.WriteLine(e.Exception.ToString());
};
tunnel.Start();
Program.RunBackup();
// ... closes the port ... //
tunnel.Stop();
client.Disconnect();
}
}
catch (UnauthorizedAccessException e)
{
Console.WriteLine(e);
}
}
I am confused since in the above, the if (client.IsConnected) returns true.
The error seems to be occurring when the Entity Framework Core OnConfiguring() method passes details of the connection with its optionsBuilder:
optionsBuilder.UseNpgsql($"Host=127.0.0.1;Port=6544;Database=user;Username=user;Password=databasePassworh;CommandTimeout=300;Timeout=300;SSL Mode=Require;Trust Server Certificate=true;Convert Infinity DateTime=true");
The errors that are arising are:
NpgsqlException: Exception while connecting
and:
ExtendedSocketException: No connection could be made because the target machine actively refused it. 127.0.0.1:6544
I have double checked all passwords, and read through all the SSH.NET documentation and code examples, and left all the previously working (via PuTTY) code untouched.
If anyone can see what I'm doing wrong, I would be grateful. C#, SSH.NET and port forwarding are new to me, please tell me where I'm being an idiot.
This code is now working. I believe the problem was that in line:
var tunnel = new ForwardedPortLocal(6544, "111.22.33.66", 6543);
the 'bound port' did not include an address. I had seen examples where this was undefined, and had followed these. On stepping through the code, I noticed that the field was blank, and decided to try 127.0.0.1. This is now successfully connecting to the database. It works with:
var tunnel = new ForwardedPortLocal("127.0.0.1", 6544, "111.22.33.66", 6543);
Thanks for looking into this and for your contributions.
This is the situation. I have a Windows machine and a Linux machine. There is a shared drive between these two machines (which is mapped to Q:). I am trying to figure out how to create an SSH session at the Q: drive (shared drive) from C#. I am trying to use the SharpSsh library to do this.
This is what I have so far, however, it is giving me an error:
try
{
ssh = new SshStream(host, username, password);
Console.WriteLine("OK ({0}/{1})", ssh.Cipher, ssh.Mac);
Console.WriteLine("Server version={0}, Client version={1}", ssh.ServerVersion, ssh.ClientVersion);
Console.WriteLine("-Use the 'exit' command to disconnect.");
Console.WriteLine();
//Sets the end of response character
ssh.Prompt = "#";
//Remove terminal emulation characters
ssh.RemoveTerminalEmulationCharacters = true;
//Reads the initial response from the SSH stream
Console.Write(ssh.ReadResponse()); // Blocking here
while (true)
{
string command = Console.ReadLine();
if (command.ToLower().Equals("exit"))
break;
//Write command to the SSH stream
ssh.Write(command);
//Read response from the SSH stream
Console.Write(ssh.ReadResponse());
}
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
if(ssh != null)
{
ssh.Close();
}
I have added the Tamir.SharpSSH.dll as a reference to the project, and I am using it in the project. There are two other dll's that are included with SharpSSH, do I need to add them as well to the references? The examples I have seen only have the Tamir.SharpSSH.dll as a reference.
I am not sure how to initiate the connection in the correct location, and how to submit commands properly to the ssh.
UPDATE
I realized I needed to close the SSH connection before ending the program. The error does not exist anymore, however, I am still not getting any information from my "ls" command.
UPDATE
I updated the code with what I have now. It seems like the ssh.ReadResponse() is blocking, which leads me to believe the server is not responding. Is that correct?
I am new to C# and Windows development in general. I need to use it to build an integration between our data in MySQL to Microsoft Dynamics GP (using eConnect). That part is not really relevant, but adds a little context to the examples below.
Ok, so when I connect to the service:
eConnectClient client = new eConnectClient();
string newCustomerDocument = "SOME_XML_HERE";
string connectionString = "Data Source=localhost;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=GPVPM;";
try
{
client.Open();
bool result = client.CreateEntity(connectionString, newCustomerDocument);
}
catch (FaultException<eConnectFault> e)
{
Console.Write("ECONNECT FAULT: " + e.ToString() + "\n");
}
Now, if I have an error in my XML, it will cause a FaultException to be thrown, but the resulting exception message is useless:
ECONNECT FAULT: System.ServiceModel.FaultException`1[GPConnect.eConnect.eConnectFault]: The creator of this fault did not specify a Reason. (Fault Detail is equal to GPConnect.eConnect.eConnectFault).
I found that if I look in the Event Viewer for Windows, it paints an entirely different picture of what happened:
Specifically:
Error Number = 250 Stored Procedure= taUpdateCreateCustomerRcd Error Description = The Tax Schedule does not exist in the Tax Schedule Master Table
So that is something actionable that can help me identify the problem and fix it.
The question:
With C#, how can I get the same level of details from an Exception as is recorded by the Event Manager?
The server may and may not return the detailed exception to the client. You may want to check
e.Detail /* of type GPConnect.eConnect.eConnectFault */
and
e.InnerException
inside the catch block for potential details.
I want to uninstall a program using WMI, but I get this error : "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))". Installing it worked without any problems, using the same ConnectionOptions.
Is there any possibility that the Administrator user has rigths to install software, but not to uninstall? If so, how can I edit them?
Main()
{
ConnectionOptions oConn = new ConnectionOptions();
oConn.Impersonation = ImpersonationLevel.Impersonate;
oConn.EnablePrivileges = true;
oConn.Username = "Administrator";
oConn.Password = "password";
System.Management.ManagementScope oMs =
new System.Management.ManagementScope("\\\\192.168.14.128\\root\\cimv2", oConn);
Uninstall(oMs, "\\\\192.168.14.128\\root\\cimv2:Win32_Product.IdentifyingNumber= \"{926C96FB-9D0A-4504-8000-C6D3A4A3118E}\",Name=\"Java DB 10.4.2.1\",Version=\"10.4.2.1\"");
}
static void Uninstall(ManagementScope oMs, string path)
{
if (!oMs.IsConnected) oMs.Connect();
ManagementObject product = new ManagementObject(path);
if ((product != null) && (product.Path.ClassName ==
"Win32_Product"))
{
object result = product.InvokeMethod("Uninstall", null); //here is where I get the error
Console.WriteLine("The Uninstall method result is {0}",
result.ToString());
}
}
Thank You!
Are you doing this on an XP machine? I just Google-d your error number and got a couple links to this: http://www.0x80070005.net/. There's a lot of information about the problem, and here's a copy and paste:
The error 0x80070005 often occurs when
a scheduled task in Task Scheduler in
Windows becomes corrupt, you need to
install a security update which will
receive an error message. The error
message usually shows “Access denied”.
Here it needs a vulnerability task
scheduler which will allow code
execution. These are security updates
which were issued in the earlier
bulletin. This needs a Microsoft
knowledge base. So it is clear that
this error is about the security issue
and it finds error in the access.
Also, we're using WiX for our installer solution. Not sure if it' something you can use, but I figured I would just throw it out there.