Get Performance counter for Clustered MSMQ - c#

I been trying reading performance counter of a Clustered MSMQ. I've gone through several post to find out a way to read this value and I've seen solution which says that to read counter value one need to create a RegistryKey named as "NetNameForPerfCounters". This is to be created under HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\MSMQ\PARAMETER\NetNameForPerfCounters and as a value I've specified the network name of my cluster. But all in vain it is not reading anything.
var category = new PerformanceCounterCategory("MSMQ Queue", "<Clustered IP>")
Console.WriteLine(category.GetInstanceNames().Count().ToString());
This always return count as 0.

You'd think that IP address would work as machineName, but I'm not sure it does. I find that using an actual machine name (".", or "acomputername") works but using an IP address fails.
I find the same in PowerShell; using IP fails:
Get-Counter -Counter (Get-Counter -ListSet "MSMQ Queue" -Computer 127.0.0.1 ).PathsWithInstances
But the same line with -computer "machinename" succeeds and shows my queues.
For larger networks, I think this means you'd need #"domainname\machinename".
https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.diagnostics/get-counter

Related

Meaning of PingException "No such host is known"

I wrote a Windows Service which monitors devices on our LAN by (among other things) pinging them (using Ping.Send(); .NET 4.6.1). For a small number of PCs (3), I "occasionally" (once/day?) will get a PingException from Send(<ipaddr>, 5000), with InnerException.Message == "No such host is known". The next time the Send() is executed (~60 seconds later), it succeeds. I am using an IP address, as opposed to a name, so it's not a DNS issue.
I talked to the network admins about this issue, but they don't believe anything is wrong with the physical hardware. What other problems could this error be indicating?
Ping.Send() has various parameters which includes a parameter type of string than can either be a valid IP address or valid host-name. I suspect that your using one of the string parameters and sometimes passing an invalid IP (extra space, invalid IP etc...) and the Send() method conditionally resolves that you must be passing a host-name hence the exception regarding DNS.
Rather than send a string, why not utilize the parameter of type IPAddress as you've already stated that it should always be an IP. You can do this by attempting to parse the string into an IPAddress as shown below:
if (IPAddress.TryParse("**IP String**", out var ip))
{
using (var pong = new Ping())
{
pong.Send(ip);
//Etc...
}
}
Note that you will still need to fix your invalid data whichever way you look at it.

Outlook Interop Exception HRESULT: 0xCA140115

I have some pretty basic code that seems to work for most people but there's at least one workstation that throws this HRESULT code when it runs these couple lines of code:
Outlook.Application _OutlookInstance = new Outlook.Application();
Outlook.Stores stores = _OutlookInstance.Session.Stores;
Any idea what HRESULT code 0xCA140115 is or what it means? I can't find it on MSDN anywhere...
The workstation that experiences the problem is at a remote call center location, so I can't do any immediate testing/debugging, or easily see what is specifically different about this workstation versus the others. I would imagine there might be more workstations at that same call center that could have the error, but this code is still in the testing phase.
Sorry for the delay, but I was able to get through several more iterations of testing and find out what the issue was. First off, my original post was incorrect. The code flow made it seem like the error was happening during those 2 initial lines, but it was actually happening a little later, when I was looping through the stores, like this:
Outlook.Stores stores = _OutlookInstance.Session.Stores;
foreach(Outlook.Store store in stores) // <----- THIS LINE
{
...
}
Each time the user ran this, he would get a different HRESULT error code:
0xCA140115
0xAF64011D
0xC1F4011D
0xC834011D
The only consistent factor was the "4011" in the middle.
When I upped the logging, I could see that the user had 18 mailboxes and the foreach() loop was getting through the first 3 but failing on the 4th. The 4th mailbox was a "Public Folders" store associated to another mailbox that was added in a different way than the rest of the mailboxes (it had something to do with it being an Outlook 365 mailbox that required different authentication).
So essentially it ended up being that any attempt to even touch that particular mailbox/store (including the "store" variable being set) would result in that COM exception.
I was able to work around it by looping through stores via numeric index so that the setting of "store" was inside my try/catch block, like this:
for(int i = 0; i < stores.Count; i++)
{
try
{
Outlook.Store store = stores[i];
...
}
catch(Exception)
{
...
}
}
Now when the loop hit that particular store, I could tell that it was Outlook saying that the server wasn't available, and the store was an online-only store, so the store couldn't be accessed.
I'm still not certain about why the error codes changed each time, but there you have it.

Item has already been added. Key in dictionary: 'Hostname' Key being added: 'Hostname' in c#

I am trying to push a message to IBM MQ but while adding properties like HostName, channel and Port I am getting below error when I continue the debug without stopping
Item has already been added. Key in dictionary: 'Hostname' Key being added: 'Hostname' in c#.
I have tried to validate as below,
if (!MQEnvironment.properties.ContainsKey(strHost) && !MQEnvironment.properties.ContainsKey(intPort) && !MQEnvironment.properties.ContainsKey(strChannel))
{
MQEnvironment.properties.Add("Hostname", strHost);
MQEnvironment.properties.Add("Port", intPort);
MQEnvironment.properties.Add("Channel", strChannel);
MQEnvironment.properties.Add(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES);
}
above code contains in my MQ PutMessage method where I am pushing my message.
Yuk (and a headache for future support).
First off, the MQEnvironment class is a static class and should ONLY be used for super simple programs. The IBM MQ best practices is to use a HashTable.
Second, why are you not using the supplied MQ defines for the key names? (it will eliminate typos)
Third, you need to review the MQ Knowledge Center for the correct MQ .NET values for 'TRANSPORT_PROPERTY'. Please see here. There are 4 valid values for MQ .NET:
MQC.TRANSPORT_MQSERIES_BINDINGS - connect as server
MQC.TRANSPORT_MQSERIES_CLIENT - connect as non-XA client
MQC.TRANSPORT_MQSERIES_XACLIENT - connect as XA client
MQC.TRANSPORT_MQSERIES_MANAGED - connect as non-XA managed client
Here is the proper way to code it:
Hashtable qMgrProp = new Hashtable();
qMgrProp.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
qMgrProp.Add(MQC.HOST_NAME_PROPERTY, strHost);
qMgrProp.Add(MQC.PORT_PROPERTY, intPort);
qMgrProp.Add(MQC.CHANNEL_PROPERTY, strChannel);
MQQueueManager qMgr = new MQQueueManager(qMgrName, qMgrProp);
It looks like it's not strHost that's already there, it's "Hostname". You'd need to change your checking to be:
MQEnvironment.properties.ContainsKey("HostName")
etc.

MongoDB C# driver: connection string for sharding over replica set

I need to setup sharding over replica set as recommended in MongoDB reference for high availability & scalability. I have few questions about connection string and its behavior for C# driver in that scenario (code snippet below):
Is the connection string below looks right for connecting to mongos instances: mongos1, mongos2 & mongos3?
What happens to client if one of the mongos instance crashes? Will the failed call handled gracefully by retrying to second mongos instance? Does the client blacklist the failed mongos instance and try after sometime?
If I want to set readpreference, will the driver be aware of replica set existence and honor setting ReadPreference?
Code snippet:
MongoUrlBuilder bldr = new MongoUrlBuilder();
List<MongoServerAddress> servers = new List<MongoServerAddress>();
servers.Add(new MongoServerAddress("mongos1:27016"));
servers.Add(new MongoServerAddress("mongos2:27016"));
servers.Add(new MongoServerAddress("mongos3:27016"));
bldr.Username = "myuser";
bldr.Password = "mypwd";
bldr.Servers = servers;
bldr.DatabaseName = "mydb";
bldr.ReadPreference = ReadPreference.Primary;
var server = MongoServer.Create(bldr.ToMongoUrl());
1) Yes, this is just fine. Note that all of this could be put in an actual connection string as well. mongodb://myuser:mypwd#mongos1:27016,mongos2:27016,mongos3:27016/mydb/?readPreference=primary
2) The way your connection string is built, you'll be load balancing across the 3 mongos. If one goes down, then the other two will simply begin to receive more traffic. Errors, however, will happen and nothing gets retried automatically. You'll need to handle the errors and make decisions based on each query/write whether it is safe to retry.
3) The driver, when talking to a sharded system, will simply forward the read preference to mongos. Note that mongos version 2.2 had some difficulty with read preferences. I'd advise you to be on the 2.4 line.

Getting wrong serial-port names from bluetoothdevice (c#)

To get all avaliable Serialports from the system i use the following command.
SerialPort.GetPortNames
It works fine for the mainboard serial port, but with the bluetooth device i get the wrong portnames.
For Example: Instead of COM7 i get sometimes COM70 or COM7ö. Its always 1 letter to much.
any suggestens?
PS: I am using newest Visual Studio Express in Windows 7
PPS: The dirty hack to cut the last letter didn't work because i don't know which one is the bluetooth serial port (with various bluetoothstick or devices it changes the number of the comport) and after trying various sticks i reached COM10, ergo COM100 or COM10f
EDIT: the code i am using right now. reading the regestry, but still the same problem.
RegistryKey myRegistry = Registry.LocalMachine.OpenSubKey("Hardware\\DeviceMap\\SerialComm");
foreach (string valuename in myRegistry.GetValueNames())
{
if (myRegistry.GetValue(valuename) is String)
{
if (valuename.Contains("BthModem"))
{
richTextBox1.AppendText(">" + myRegistry.GetValue(valuename) + "<" + Environment.NewLine);
}
}
}
Normally the second or third request is working with a result like
COM11ᯋ<
COM10S<
COM11<
COM10<
COM11<
COM10<
how can that be?
This has been reported as a bug with non-null terminated strings:
Can you manually walk the registry?
HKLM\Hardware\DeviceMap\SerialComm
You can utilize WMI to query the system for serial ports, including those that are added by bluetooth devices and USB-To-Serial devices. Maybe that way you won't encounter this issue. See at CodeProject.
I have the same issue. SerialPort.GetPortNames basically uses the registry anyway- both of those methods don't seem to work with bluetooth.
The workaround I'm currently using is to loop through the first X com ports and see if they exist, which is hardly elegant. MS: FAIL.

Categories