Following this post: Get Active QM Instance from Multi Instance Queue Manager and connect
I have created a connection
XMSFactoryFactory factory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
IConnectionFactory connectionProperties = factory.CreateConnectionFactory();
connectionProperties.SetIntProperty(XMSC.WMQ_CLIENT_RECONNECT_OPTIONS, XMSC.WMQ_CLIENT_RECONNECT_Q_MGR);
connectionProperties.SetStringProperty(XMSC.WMQ_CONNECTION_NAME_LIST, String.Format("{0}({1}),{2}({3})", element.Host1, element.Port1, element.Host2, element.Port2));
connectionProperties.SetIntProperty(XMSC.WMQ_CLIENT_RECONNECT_TIMEOUT, XMSC.WMQ_CLIENT_RECONNECT_TIMEOUT_DEFAULT);
connectionProperties.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, element.QueueManager);
connectionProperties.SetStringProperty(XMSC.WMQ_CHANNEL, element.Channel);
connectionProperties.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
connectionProperties.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1);
connectionProperties.SetBooleanProperty(XMSC.WMQ_USE_CONNECTION_POOLING, true);
then followed by
try
{
using (IConnection connection = _connectionProperties.CreateConnection())
{
connection.Start();
using (ISession session = connection.CreateSession(true, AcknowledgeMode.AutoAcknowledge))
{
using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
using (IDestination responseQueue = session.CreateQueue(replyToRequestQueue ? _requestQueueName : _responseQueueName))
{
using (IMessageProducer producer = session.CreateProducer(responseQueue))
{
IMessage response = session.CreateTextMessage(message);
if (!string.IsNullOrEmpty(correlationId))
{
response.JMSCorrelationID = correlationId;
}
producer.Send(response);
}
}
scope.Complete();
}
}
}
}
catch (XMSException xmse)
{
if (xmse.LinkedException != null)
{
Trace.TraceError(string.Format(MQTraceMessageFormat,
DateTime.Now,
TraceMessageType.Error,
Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.IsThreadPoolThread ? "Threadpool " + Name : Thread.CurrentThread.Name,
null, null,
"XMSException.LinkedException on (SendTextMessage) sending message to " + this +
" / xmse.LinkedException.Message : " + xmse.LinkedException.Message +
" / xmse.Message : " + xmse.Message +
" / xmse.LinkedException.StackTrace: " + xmse.LinkedException.StackTrace,
" / xmse.StackTrace: " + xmse.StackTrace,
null));
}
else
{
Trace.TraceError(string.Format(MQTraceMessageFormat,
DateTime.Now,
TraceMessageType.Error,
Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.IsThreadPoolThread ? "Threadpool " + Name : Thread.CurrentThread.Name,
null, null,
"XMSException on (SendTextMessage) sending message to " + this +
" / xmse.Message : " + xmse.Message +
" / xmse.StackTrace: " + xmse.StackTrace,
null));
}
}
catch (MQException mqex)
{
Trace.TraceError(string.Format(MQTraceMessageFormat,
DateTime.Now,
TraceMessageType.Error,
Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.IsThreadPoolThread ? "Threadpool " + Name : Thread.CurrentThread.Name,
null, null,
"MQException cc on (SendTextMessage) sending message to " + this +
" Exception: " + mqex.Message +
" CompletionCode: " + mqex.CompletionCode +
" ReasonCode: " + mqex.ReasonCode +
" Stack Trace: " + mqex.StackTrace,
null));
}
catch (IOException ioex)
{
Trace.TraceError(string.Format(MQTraceMessageFormat,
DateTime.Now,
TraceMessageType.Error,
Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.IsThreadPoolThread ? "Threadpool " + Name : Thread.CurrentThread.Name,
null, null,
"IOException ioex on (SendTextMessage) sending message to " + this +
" Exception: " + ioex.Message +
" Stack Trace: " + ioex.StackTrace,
null));
}
catch (Exception ex)
{
Trace.TraceError(string.Format(MQTraceMessageFormat,
DateTime.Now,
TraceMessageType.Error,
Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.IsThreadPoolThread ? "Threadpool " + Name : Thread.CurrentThread.Name,
null, null,
"Exception ex on (SendTextMessage) sending message to " + this +
" Exception: " + ex.Message +
" Stack Trace: " + ex.StackTrace,
null));
}
}
to send message, however it threw exception at the last line producer.Send(response):
renamed.exe Error: 0 : |8/15/2017 10:17:49 AM|Error|25|Threadpool XYZ|||XMSException.LinkedException on (SendTextMessage) sending message to Queue handler ABC:(In ABC.XYZ.REQUEST / Out XYZ.ABC.RESPONSE) / xmse.LinkedException.Message : 2012 / xmse.Message : Failed to send a message to destination XYZ.ABC.RESPONSE.
XMS attempted to perform an MQPUT or MQPUT1; however WebSphere MQ reported an error.
Use the linked exception to determine the cause of this error. / xmse.LinkedException.StackTrace: | / xmse.StackTrace: at IBM.XMS.Client.WMQ.ProducerShadow.CheckNmqiCallSuccess(String messageid, WmqDestination destination, String probeid, Int32 cc, Int32 rc)
at IBM.XMS.Client.WMQ.SpiIdentifiedProducerShadow.SendInternal(MQMessageDescriptor md, Byte[] buffers, Int32 msgLength)
at IBM.XMS.Client.WMQ.ProducerShadow.Send(WmqDestination destAtSendCall, WmqMessage message)
at IBM.XMS.Client.WMQ.WmqMessageProducer.Send(ProviderDestination destAtSendCall, ProviderMessage message)
at IBM.XMS.Client.Impl.XmsMessageProducerImpl.SendMessage(IMessage message, XmsDestinationImpl dest)
at IBM.XMS.Client.Impl.XmsMessageProducerImpl.Send_(Boolean inIdentifiedContext, XmsDestinationImpl dest, IMessage message, DeliveryMode deliveryMode, Int32 priority, Int64 timeToLive, Boolean explicitDlvModePriorityAndTimeToLive)
at IBM.XMS.Client.Impl.XmsMessageProducerImpl.Send(IMessage message)
at DVS.Services.Common.MQHandler.QueueHandler.SendTextMessage(String message, String correlationId, Boolean replyToRequestQueue)
From the trace I can see the producer has my two active/standby host in the connection name list, but also "localhost" as host_name and 1414 as port, is that why I cannot connect to it?
producer: XMSC_WMQ_BROKER_PUBQ_QMGR :
XMSC_CONNECTION_TYPE_NAME : IBM.XMS.Client.WMQ
XMSC_DISABLE_MSG_ID : False
XMSC_WMQ_RESOLVED_QUEUE_MANAGER_ID : QM1_2017-08-02_15.25.10
XMSC_WMQ_CLEANUP_INTERVAL : 3600000
XMSC_WMQ_BROKER_PUBQ : SYSTEM.BROKER.DEFAULT.STREAM
XMSC_WMQ_BROKER_SUBQ : SYSTEM.JMS.ND.SUBSCRIBER.QUEUE
XMSC_WMQ_PUB_ACK_INTERVAL : 25
targetClient : 0
XMSC_WMQ_CLEANUP_LEVEL : 1
XMSC_WMQ_MESSAGE_RETENTION : 1
XMSC_WMQ_PORT : 1414
XMSC_WMQ_PROVIDER_VERSION : 7
CCSID : 1208
deliveryMode : 2
XMSC_ADMIN_OBJECT_TYPE : 20
brokerVersion : 0
XMSC_WMQ_USE_CONNECTION_POOLING : True
XMSC_WMQ_TEMP_Q_PREFIX :
XMSC_ACKNOWLEDGE_MODE : 4
XMSC_WMQ_BROKER_CONTROLQ : SYSTEM.BROKER.CONTROL.QUEUE
failIfQuiesce : 1
XMSC_WMQ_MESSAGE_SELECTION : 0
XMSC_ASYNC_EXCEPTIONS : -1
timeToLive : 0
XMSC_WMQ_CONNECTION_MODE : 1
XMSC_WMQ_RESOLVED_QUEUE_MANAGER : QM1
XMSC_WMQ_CONNECTION_NAME_LIST : host1(11111),host2(11111)
XMSC_WMQ_QMGR_CCSID : 819
XMSC_WMQ_SHARE_CONV_ALLOWED : 1
XMSC_WMQ_CLIENT_RECONNECT_TIMEOUT : 1800
XMSC_WMQ_MAP_NAME_STYLE : True
XMSC_PASSWORD : ********
priority : 4
XMSC_WMQ_LOCAL_ADDRESS :
XMSC_WMQ_MAX_BUFFER_SIZE : 1000
XMSC_WMQ_CONNECT_OPTIONS : 0
XMSC_DISABLE_MSG_TS : False
XMSC_WMQ_BROKER_QMGR :
XMSC_WMQ_CLIENT_RECONNECT_OPTIONS : 16777216
version : 7
XMSC_WMQ_CONNECTION_TAG : System.Byte[]
encoding : 546
XMSC_WMQ_POLLING_INTERVAL : 5000
XMSC_WMQ_RESCAN_INTERVAL : 5000
XMSC_WMQ_TEMPORARY_MODEL : SYSTEM.DEFAULT.MODEL.QUEUE
XMSC_WMQ_CHANNEL : MY.SVC.SVRCONN.P
XMSC_CONNECTION_TYPE : 1
XMSC_WMQ_SYNCPOINT_ALL_GETS : False
XMSC_WMQ_HOST_NAME : localhost
XMSC_WMQ_QUEUE_MANAGER : QM1
wildcardFormat : 0
XMSC_WMQ_BROKER_DUR_SUBQ : SYSTEM.JMS.D.SUBSCRIBER.QUEUE
XMSC_TRANSACTED : True
XMSC_WMQ_MSG_BATCH_SIZE : 10
Automatic Client Reconnection with Distributed Transactions are not supported that is the reason you see
|XMSException.LinkedException on (SendTextMessage) sending message to Queue handler ABC:(In ABC.XYZ.REQUEST / Out XYZ.ABC.RESPONSE) / xmse.LinkedException.Message : **2012** / xmse.Message : Failed to send a message to destination XYZ.ABC.RESPONSE.
2012 is MQRC_ENVIRONMENT_ERROR.
Following link talks about it :https://www.ibm.com/support/knowledgecenter/SSFKSJ_9.1.0/com.ibm.mq.con.doc/q018380_.htm
Related
I have this Raw ESC/POS command for LX-300+, and i want to print it through Print Server using Socket.
String escp = " '\x1B' + '\x40', // initialize the printer, reset printer to defaults " +
" '\x1B' + '\x78' + '\x31', // Set Print Quality NLQ " +
" '\x1B' + '\x6B' + '\x31', // Select typeface San serif " +
" '\x1B' + '\x43' + '\x00' + '\x06', // set Page Length to 6 Inch " +
" '\x1B' + '\x4D', // Select 12 cpi Spacing " +
" '\x1B' + '\x45', // SET Bold Font ";
Question is, can we parse that String of escp with Socket? i use this code,
Socket socket = null;
OutputStream output = null;
BufferedReader reader = null;
try {
socket = new Socket("10.0.5.30", 9100);
socket.setSoTimeout(5000);
output = socket.getOutputStream();
reader = new BufferedReader(new java.io.InputStreamReader(socket.getInputStream()));
} catch (UnknownHostException e) {
// TODO: handle exception
}
if (socket != null && output != null) {
try
{
output.write(escp.getBytes());
output.flush();
socket.shutdownOutput();
output.close();
socket.close();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
The result is, printer LX-300 is not converting the ESC/POS Command. Just print the String inside escp variable. Any solution to this? i'm using linux 18.04 FYI.
The UI Editor in Dynamics CRM won't allow system admins to directly edit status/statecode picklists on the Activity Entity. How can the order be edited programatically?
In another question, information is provided about how to get metadata about statuscodes and statecodes:
Dynamics Crm: Get metadata for statuscode/statecode mapping
Microsoft provides a class for sorting order of picklists:
https://learn.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg327607(v%3dcrm.8)
I have successsfully coded and can retrieve metadata for both standard picklists and for statuscodes picklists (both the statecode and statuscode). I can programatically update the sort order on standard picklists, but when attempting to do so on a statuscode optionset, no errors are thrown and no changes are published to the system.
How can the sort order on the activity statuscode field be updated?
Example code follows, complete with both tests:
namespace ConsoleApps
{
class EditAptStatusCodeOptionSetOrder
{
static void Main()
{
//Connect to Database
string CRMConnectionString = #"AuthType = Office365; URL = https://URLOFSERVER; Username=USERNAME; Password=PASSWORD;";
Console.WriteLine("Connecting to Auric Solar Sandbox Environment Using Ryan Perry's Credentials. ");
CrmServiceClient crmServiceClient = new CrmServiceClient(CRMConnectionString);
IOrganizationService crmService = crmServiceClient.OrganizationServiceProxy;
//Test Retrieving Stage (Statuscode) from Test Entity.
//Get the Attribute
RetrieveAttributeRequest retrieveStatusCodeAttributeRequest = new RetrieveAttributeRequest
{
EntityLogicalName = "new_testentity",
LogicalName = "statuscode",
RetrieveAsIfPublished = true
};
RetrieveAttributeResponse retrieveStatusCodeAttributeResponse =
(RetrieveAttributeResponse)crmService.Execute(retrieveStatusCodeAttributeRequest);
Console.WriteLine("Retreived Attribute:" +
retrieveStatusCodeAttributeResponse.AttributeMetadata.LogicalName);
Console.WriteLine("Retreived Attribute Description:" +
retrieveStatusCodeAttributeResponse.AttributeMetadata.Description);
StatusAttributeMetadata statusCodeMetaData =
(StatusAttributeMetadata)retrieveStatusCodeAttributeResponse.AttributeMetadata;
Console.WriteLine("Metadata Description:" +
statusCodeMetaData.Description);
Console.WriteLine("Metadata IsValidForUpdate:" +
statusCodeMetaData.IsValidForUpdate.ToString());
Console.WriteLine("OptionSet Type:" +
statusCodeMetaData.OptionSet.Name.ToString());
Console.WriteLine("OptionSet Name:" +
statusCodeMetaData.OptionSet.OptionSetType.ToString());
Console.WriteLine("Retrieved Options:");
foreach (OptionMetadata optionMeta in statusCodeMetaData.OptionSet.Options)
{
Console.WriteLine(((StatusOptionMetadata)optionMeta).State.Value + " : " + optionMeta.Value + " : " + optionMeta.Label.UserLocalizedLabel.Label);
}
//Save Options in an array to reorder.
OptionMetadata[] optionList = statusCodeMetaData.OptionSet.Options.ToArray();
Console.WriteLine("Option Array:");
foreach (OptionMetadata optionMeta in optionList)
{
Console.WriteLine(((StatusOptionMetadata)optionMeta).State.Value + " : " + optionMeta.Value + " : " + optionMeta.Label.UserLocalizedLabel.Label);
}
var sortedOptionList = optionList.OrderBy(x => x.Label.LocalizedLabels[0].Label).ToList();
Console.WriteLine("Sorted Option Array:");
foreach (OptionMetadata optionMeta in sortedOptionList)
{
Console.WriteLine(((StatusOptionMetadata)optionMeta).State.Value + " : " + optionMeta.Value + " : " + optionMeta.Label.UserLocalizedLabel.Label);
}
//Create the request.
OrderOptionRequest orderStatusCodeOptionRequest = new OrderOptionRequest
{
AttributeLogicalName = "statuscode",
EntityLogicalName = "new_testentity",
Values = sortedOptionList.Select(X => X.Value.Value).ToArray()
};
Console.WriteLine("orderStatusCodeOptionRequest Created.");
//Execute Request. //////THIS DOESN'T THROW ERRORS, BUT DOESN'T UPDATE SYSTEM.
OrderOptionResponse orderStatusCodeResponse = (OrderOptionResponse)crmService.Execute(orderStatusCodeOptionRequest);
Console.WriteLine("Request Executed");
////////////////////////////////////////PICKLIST TEST//////////////////////////////////
Console.WriteLine("\n\nTestingPickList");
RetrieveAttributeRequest retrieveTestPicklistAttributeRequest = new RetrieveAttributeRequest
{
EntityLogicalName = "new_testentity",
LogicalName = "new_testpicklist",
RetrieveAsIfPublished = true
};
RetrieveAttributeResponse retrieveTestPicklistAttributeResponse =
(RetrieveAttributeResponse)crmService.Execute(retrieveTestPicklistAttributeRequest);
PicklistAttributeMetadata pickListMetaData =
(PicklistAttributeMetadata)retrieveTestPicklistAttributeResponse.AttributeMetadata;
Console.WriteLine("Retrieved Picklist Options:");
foreach (OptionMetadata optionMeta in pickListMetaData.OptionSet.Options)
{
Console.WriteLine(optionMeta.Value + " : " + optionMeta.Label.UserLocalizedLabel.Label);
}
//Save Options in an array to reorder.
OptionMetadata[] picklistOptionList = pickListMetaData.OptionSet.Options.ToArray();
Console.WriteLine("Picklist Option Array:");
foreach (OptionMetadata optionMeta in picklistOptionList)
{
Console.WriteLine(optionMeta.Value + " : " + optionMeta.Label.UserLocalizedLabel.Label);
}
var sortedPicklistOptionList = picklistOptionList.OrderBy(x => x.Label.LocalizedLabels[0].Label).ToList();
Console.WriteLine("Picklist Sorted Option Array:");
foreach (OptionMetadata optionMeta in sortedPicklistOptionList)
{
Console.WriteLine(optionMeta.Value + " : " + optionMeta.Label.UserLocalizedLabel.Label);
}
//Create the request.
OrderOptionRequest orderPicklistOptionRequest = new OrderOptionRequest
{
AttributeLogicalName = "new_testpicklist",
EntityLogicalName = "new_testentity",
Values = sortedPicklistOptionList.Select(X => X.Value.Value).ToArray()
};
Console.WriteLine("orderPicklistOptionRequest Created.");
//Execute Request.
OrderOptionResponse orderPicklistResponse = (OrderOptionResponse)crmService.Execute(orderPicklistOptionRequest);
Console.WriteLine("Order Picklist Request Executed");
//Publish All.
Console.WriteLine("Publishing. Please Wait...");
PublishAllXmlRequest publishRequest = new PublishAllXmlRequest();
crmService.Execute(publishRequest);
Console.WriteLine("Done.");
Console.ReadLine();
}
}
}
I am getting below error in my function.
Error: FROM keyword not found where expected
And here is my Function:
private int BauteilLieferzeit(string Materianummer)
{
try
{
OracleCommand cmd = new OracleCommand(
" Select MATNR, AVG_DAUER" +
" AVG " +
" (DATEDIFF " +
" (mi, Z.APL_ANFDATUM, " +
" Z.STA_LIEFERDATUM)) " +
" as AVG_DAUER " +
" from ZDATA AS Z " +
" where MATNR = '" + Materianummer + "'"
, OraVerbindung._conn);
OracleDataReader r = cmd.ExecuteReader();
if (r.HasRows)
{
int Restminuten = OraVerbindung.Lieferzeit;
while (r.Read())
{
Restminuten = r.GetInt32(1);
}
return Restminuten;
}
else
{
return OraVerbindung.Lieferzeit;
}
}
catch
{
return OraVerbindung.Lieferzeit;
}
}
In Oracle this is not a valid syntax
from ZDATA AS Z
use
from ZDATA Z
instead (remove "AS")
Additionally consider the use of bind variables instead of string concatenation:
" where MATNR = '" + Materianummer + "'"
search for "SQL Injection".
Use this. Included the issue highlighted by Marmite also. But the error FROM keyword not found where expected would be due to missing comma in select statement.
Edit: Removed AVG_DAUER column as it is getting derived later.
private int BauteilLieferzeit(string Materianummer)
{
try
{
OracleCommand cmd = new OracleCommand(
" Select MATNR," +
" AVG " +
" (DATEDIFF " +
" (mi, Z.APL_ANFDATUM, " +
" Z.STA_LIEFERDATUM)) " +
" as AVG_DAUER " +
" from ZDATA Z " +
" where MATNR = '" + Materianummer + "'"
, OraVerbindung._conn);
OracleDataReader r = cmd.ExecuteReader();
if (r.HasRows)
{
int Restminuten = OraVerbindung.Lieferzeit;
while (r.Read())
{
Restminuten = r.GetInt32(1);
}
return Restminuten;
}
else
{
return OraVerbindung.Lieferzeit;
}
}
catch
{
return OraVerbindung.Lieferzeit;
}
}
I am using BaseX (XML based datastore) for its performance benchmarking. For testing it with ,
TestBeds
I) 10,000 users, 10 friends, 10 resources
II) 100,000 users , 10 friends, 10 resources
I faced below issues:
1) Loading of data is too slow. Gets slowed with eh increase in the number of threads.
2) Plus point - Reading/retriving values from BaseX is faster (17k operation per second)
3) Updating the data in BaseX is very slow. Throughput is ~10 operations per second.
Am I correct to say BaseX is 'TOO' slow for write/update operations (20/sec) compared to read/retrieve (10k/sec)?
Please advice me to make it more efficient for the write and update :
I have a function insertEntity (update or insert function) in to the BaseX datastore as follows -
public int insertEntity(String entitySet, String entityPK,
HashMap<String, ByteIterator> values, boolean insertImage) {
String parentTag ="",childTag ="", key="", entryTag="";
StringBuffer insertData = new StringBuffer();
Set<String> keys = values.keySet();
Iterator<String> iterator = keys.iterator();
while(iterator.hasNext()) {
String entryKey = iterator.next();
if(!(entryKey.equalsIgnoreCase("pic") || entryKey.equalsIgnoreCase("tpic")))
insertData.append("element " + entryKey + " {\"" + StringEscapeUtils.escapeXml(values.get(entryKey).toString()) + "\"},");
}
if(entitySet.equalsIgnoreCase("users")&& insertImage){
byte[] profileImage = ((ObjectByteIterator)values.get("pic")).toArray();
String encodedpImage = DatatypeConverter.printBase64Binary(profileImage);
insertData.append(" element pic {\"" + encodedpImage + "\"},");
profileImage = ((ObjectByteIterator)values.get("tpic")).toArray();
encodedpImage = DatatypeConverter.printBase64Binary(profileImage);
insertData.append(" element tpic {\"" + encodedpImage + "\"},");
}
if(entitySet.equalsIgnoreCase("users"))
{
parentTag = "users";
childTag = "members";
entryTag = "member";
key = "mem_id";
insertData.append("element confirmed_friends {}, element pending_friends {}");
}
if(entitySet.equalsIgnoreCase("resources"))
{
parentTag = "resources";
childTag = "resources";
entryTag = "resource";
key = "rid";
insertData.append("element manipulations {}");
}
try {
session.execute(new XQuery(
"insert node element " + entryTag
+ "{ attribute " + key + "{"
+ entityPK + "}, "
+ insertData.toString()
+ "} "
+ "into doc('" + databaseName + "/" + parentTag +".xml')/" + childTag
));
String q1 = "insert node element " + entryTag
+ "{ attribute " + key + "{"
+ entityPK + "}, "
+ insertData.toString()
+ "} "
+ "into doc('" + databaseName + "/" + parentTag +".xml')/" + childTag;
System.out.println(q1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
And the below function is acceptFriendship (update function)
public int acceptFriend(int inviterID, int inviteeID) {
// TODO Auto-generated method stub
String acceptFriendQuery1 = "insert node <confirmed_friend id = '"
+ inviterID + "'>"
+ " </confirmed_friend>"
+ "into doc('"+databaseName+"/users.xml')/members/member[#mem_id = '"+inviteeID+"']/confirmed_friends";
String acceptFriendQuery2 = "insert node <confirmed_friend id = '"
+ inviteeID + "'>"
+ " </confirmed_friend>"
+ "into doc('"+databaseName+"/users.xml')/members/member[#mem_id = '"+inviterID+"']/confirmed_friends";
String acceptFriendQuery3 = "delete node doc('"+databaseName+"/users.xml')/members/member[#mem_id = '"
+ inviteeID + "']/pending_friends/pending_friend[#id = '"+ inviterID +"']";
try {
session.execute(new XQuery(acceptFriendQuery1));
session.execute(new XQuery(acceptFriendQuery2));
session.execute(new XQuery(acceptFriendQuery3));
System.out.println("Inviter: "+inviterID +" AND Invitee: "+inviteeID);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
I want to list all users of a Windows domain with WMI in C#.
Can someone help me?
Here is my code:
try
{
ConnectionOptions connection = new ConnectionOptions();
connection.Username = user;
connection.Authority = "ntlmdomain:" + domain;
connection.Password = pwd;
SelectQuery query = new SelectQuery("SELECT * FROM Win32_UserAccount");
ManagementScope scope = new ManagementScope(#"\\FullComputerName\\root\\CIMV2", connection);
scope.Connect();
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("Account Type: " + queryObj["AccountType"]);
Console.WriteLine("Caption: " + queryObj["Caption"]);
Console.WriteLine("Description: " + queryObj["Description"]);
Console.WriteLine("Disabled: " + queryObj["Disabled"]);
Console.WriteLine("Domain: " + queryObj["Domain"]);
Console.WriteLine("Full Name: " + queryObj["FullName"]);
Console.WriteLine("Local Account: " + queryObj["LocalAccount"]);
Console.WriteLine("Lockout: " + queryObj["Lockout"]);
Console.WriteLine("Name: " + queryObj["Name"].ToString());
Console.WriteLine("Password Changeable: " + queryObj["PasswordChangeable"]);
Console.WriteLine("Password Expires: " + queryObj["PasswordExpires"]);
Console.WriteLine("Password Required: " + queryObj["PasswordRequired"]);
Console.WriteLine("SID: " + queryObj["SID"]);
Console.WriteLine("SID Type: " + queryObj["SIDType"]);
Console.WriteLine("Status: " + queryObj["Status"]);
Console.WriteLine("");
}
}
catch (ManagementException err)
{
Console.WriteLine("An error occured while querying for WMI data: " + err.Message);
}
catch (System.UnauthorizedAccessException unauthorizedErr)
{
Console.WriteLine("Connection error " + "(user name or password might be incorrect): " + unauthorizedErr.Message);
}
There's a typo in the namespace path in your ManagementScope constructor:
ManagementScope scope = new ManagementScope(#"\\FullComputerName\\root\\CIMV2", connection);
The string should be either #"\\FullComputerName\root\CIMV2" or "\\\\FullComputerName\\root\\CIMV2".
Note that you cannot specify the user account for local connections. So if FullComputerName is a local computer, use this instead:
ManagementScope scope = new ManagementScope("root\\CIMV2");