[英]Failed to load mqe.dll using impersonation
I am trying to connect to a IBM MQ queue manager using local user created on the system. 我正在尝试使用在系统上创建的本地用户连接到IBM MQ队列管理器。
I am using Win server 2008 R2, IBM MQ client and Server versions are 8.0.0.6 我正在使用Win Server 2008 R2,IBM MQ客户端和服务器版本是8.0.0.6
To run the code as a local user I have implemented impersonation. 为了以本地用户身份运行代码,我已经实现了模拟。 Now when I impersonate the user and try to connect I get below connection error.
现在,当我模拟用户并尝试连接时,出现以下连接错误。 When I run visual studio as a different user (local user), it works but not when I use impersonation.
当我以其他用户(本地用户)的身份运行Visual Studio时,它可以工作,但是当我使用模拟时却不能。
Below is the trace: 下面是跟踪:
System.TypeInitializationException was unhandled
HResult=-2146233036
Message=The type initializer for 'IBM.WMQ.MQQueueManager' threw an exception.
Source=amqmdnet
TypeName=IBM.WMQ.MQQueueManager
StackTrace:
at IBM.WMQ.MQQueueManager..ctor(String queueManagerName, String Channel, String ConnName)
at MQExample.MQTest.ConnectMQ(String strQueueManagerName, String strQueueName, String strChannelInfo) in D:\Adidas\MQExample\MQExample\MQExample\MQTest.cs:line 83
at MQExample.Form1.button1_Click(Object sender, EventArgs e) in D:\Adidas\MQExample\MQExample\MQExample\Form1.cs:line 33
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at MQExample.Program.Main() in D:\Adidas\MQExample\MQExample\MQExample\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
HResult=-2146232828
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
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.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at IBM.WMQ.CommonServices.CreateCommonServices()
at IBM.WMQ.CommonServices.TraceConstructor(String objectId, String sccsid)
at IBM.WMQ.Nmqi.NmqiEnvironment..ctor(NmqiPropertyHandler nmqiPropertyHandler)
at IBM.WMQ.Nmqi.NmqiFactory.GetInstance(NmqiPropertyHandler properties)
at IBM.WMQ.MQQueueManager..cctor()
InnerException:
HResult=-2146232828
Message=Exception has been thrown by the target of an invocation.
Source=amqmdnet
StackTrace:
at IBM.WMQ.MQCommonServices..ctor()
InnerException:
HResult=-2146233088
Message=Failed to load mqe.dll from folder C:\Program Files\IBM\WebSphere MQ\bin\
Source=amqmdnet
StackTrace:
at IBM.WMQ.Nmqi.NativeManager.InitializeNativeApis(String mode)
InnerException:
code to implement it : 实现它的代码:
using (new Tools.Impersonator("iibadmin", ".", "Test@1234"))
{
string userafter = WindowsIdentity.GetCurrent().Name;
MQQueueManager queueManager = null;
queueManager = new MQQueueManager(QueueManagerName, channelName, connectionName);
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE | MQC.MQOO_FAIL_IF_QUIESCING;
queue = queueManager.AccessQueue(QueueName, openOptions);
int depth = queue.CurrentDepth;
queueMessage = new MQMessage();
queueMessage.Format = MQC.MQFMT_STRING;
queueGetMessageOptions = new MQGetMessageOptions();
queue.Get(queueMessage, queueGetMessageOptions);
strReturn =
queueMessage.ReadString(queueMessage.MessageLength);
queue.Close();
queueManager.Disconnect();
}
Your impersonated user probably does not have the MQ environment setup. 您的模拟用户可能没有MQ环境设置。
ie Environment variables: 即环境变量:
PATH
LIB
MQ_JAVA_DATA_PATH
MQ_JAVA_INSTALL_PATH
MQ_JAVA_LIB_PATH
MQ_JRE_PATH
If you are running 32-bit .NET then you need to point to the 32-bit MQ environment like wise for 64-bit. 如果运行的是32位.NET,则需要指向32位MQ环境,就像明智的选择64位一样。
ie mqe.dll is found in: 即在以下位置找到mqe.dll:
C:\Program Files\IBM\WebSphere MQ\bin\mqe.dll
C:\Program Files\IBM\WebSphere MQ\bin64\mqe.dll
Hence, it is a good idea to know what you are running and what MQ environment you need to setup. 因此,最好知道正在运行什么以及需要设置哪个MQ环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.