如何从代码中设置 MQQueueManager 的 CCSID?

发布于 2024-12-08 02:45:30 字数 2159 浏览 0 评论 0 原文

我有一些奇怪的问题。我认为我正确地遵循了文档,但我的代码不起作用。我有一个非常简单的硬编码测试 (NUnit):

[TestFixture]
public class MQQueueTests {

    public const string MessageContent = "<test>This is test message</test>";

    public static void Main(string[] args) {
        var tests = new MQQueueTests();
        tests.PutAndGetMessage();
    }

    [Test]
    public void PutAndGetMessage() {
        var properties = new Hashtable
                             {
                                 {MQC.HOST_NAME_PROPERTY, "TestServer"},
                                 {MQC.CHANNEL_PROPERTY, "Test.Channel"},
                                 {MQC.PORT_PROPERTY, 1415},
                                 // Is this correct? It looks like it is not 
                                 // enough because adding this line didn't solve 
                                 // the problem.
                                 {MQC.CCSID_PROPERTY, 437}  
                             };

        using (var manager = new MQQueueManager("Test.Queue.Manager", properties)) {
            using (MQQueue queue = manager.AccessQueue("Test.Queue", 
                MQC.MQOO_OUTPUT | MQC.MQOO_INPUT_AS_Q_DEF)) {

                MQMessage message = new MQMessage();
                message.WriteUTF(MessageContent);
                queue.Put(message);

                MQMessage readMessage = new MQMessage();
                queue.Get(readMessage);

                Assert.AreEqual(MessageContent, readMessage.ReadUTF());

                queue.Close();
            }
            manager.Disconnect();
        }
    }
}

我从控制台或通过 Resharper 6 测试运行程序运行测试应用程序。如果我在测试运行器中运行应用程序,我总是会遇到以下异常:

IBM.WMQ.MQException:MQRC_CHANNEL_CONFIG_ERROR(原因代码为 2539)

异常由 MQQueueManager.Connect(由其构造函数调用)引发。

如果我检查 MQ 日志,我会看到:

AMQ9541:不支持为数据转换提供的 CCSID。

说明:程序结束是因为源 CCSID '437' 或者目标 CCSID“852”无效,或当前不受支持。

操作:更正无效的 CCSID,或确保 可以支持请求的CCSID。

如果我从控制台运行应用程序,我会得到相同的错误,但如果我通过调用

chcp 437

“我的测试应用程序”更改控制台的代码页,则会出现相同的错误。如何从代码配置代码页?

I have some strange problem. I think I followed documentation correctly but my code doesn't work. I have this very simple hard coded test (NUnit):

[TestFixture]
public class MQQueueTests {

    public const string MessageContent = "<test>This is test message</test>";

    public static void Main(string[] args) {
        var tests = new MQQueueTests();
        tests.PutAndGetMessage();
    }

    [Test]
    public void PutAndGetMessage() {
        var properties = new Hashtable
                             {
                                 {MQC.HOST_NAME_PROPERTY, "TestServer"},
                                 {MQC.CHANNEL_PROPERTY, "Test.Channel"},
                                 {MQC.PORT_PROPERTY, 1415},
                                 // Is this correct? It looks like it is not 
                                 // enough because adding this line didn't solve 
                                 // the problem.
                                 {MQC.CCSID_PROPERTY, 437}  
                             };

        using (var manager = new MQQueueManager("Test.Queue.Manager", properties)) {
            using (MQQueue queue = manager.AccessQueue("Test.Queue", 
                MQC.MQOO_OUTPUT | MQC.MQOO_INPUT_AS_Q_DEF)) {

                MQMessage message = new MQMessage();
                message.WriteUTF(MessageContent);
                queue.Put(message);

                MQMessage readMessage = new MQMessage();
                queue.Get(readMessage);

                Assert.AreEqual(MessageContent, readMessage.ReadUTF());

                queue.Close();
            }
            manager.Disconnect();
        }
    }
}

I'm running the test application either from console or through Resharper 6 test runner. If I run the application in test runner I always get following exception:

IBM.WMQ.MQException : MQRC_CHANNEL_CONFIG_ERROR (reason code is 2539)

The exception is thrown by MQQueueManager.Connect (called by its constructor).

If I check MQ logs I see:

AMQ9541: CCSID supplied for data conversion not supported.

EXPLANATION: The program ended because, either the source CCSID '437'
or the target CCSID '852' is not valid, or is not currently supported.

ACTION: Correct the CCSID that is not valid, or ensure that the
requested CCSID can be supported.

If I run the application from the console I got the same error but if I change the code page for console by calling

chcp 437

My test application works. How can I configure code page from code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨后咖啡店 2024-12-15 02:45:30

好吧,我找到了一个解决方法 - 它可能可以解决我的问题,但我对此不太满意。我可以全局设置 MQCCSID 环境变量,也可以通过调用:

Environment.SetEnvironmentVariable("MQCCSID", "437");

这将配置代码页。我仍然想使用新的 MQQueueManager 实例的属性来设置代码页。

Well I found a workaround - it can probably solve my problem but I'm not very satisfied with it. I can set up MQCCSID environment variable either globally or by calling:

Environment.SetEnvironmentVariable("MQCCSID", "437");

That will configure code page. Still I would like to use properties of a new MQQueueManager instance to setup code page.

街角迷惘 2024-12-15 02:45:30

这两个答案都是正确的。对于 Windows 窗体项目,将环境变量 MQCCSID 设置为与您尝试连接的队列管理器的 ccsid 相同的值就足够了。
- 第二个解决方案

HKEY_LOCAL_MACHINE->SYSTEM->CurrentControlSet->Control->Nls->CodePage>OEMCP 值。

我有一个网络应用程序(网络表单),仅适用于第二个解决方案

Both of these are answers correct. For Windows Forms Project setting the environment variable MQCCSID the same as the ccsid of the Queue Manager that you are trying to connect will be enough.
- the 2nd solution

HKEY_LOCAL_MACHINE->SYSTEM->CurrentControlSet->Control->Nls->CodePage>OEMCP value.

i had a web application(web forms) that only worked with the 2nd solution

·深蓝 2024-12-15 02:45:30

在 Windows 7 区域设置 -> 中将系统区域设置更改为英语(美国)管理->更改系统区域设置。完成此操作后,您还可以在 regedit 值中检查它。
regedit->HKEY_LOCAL_MACHINE->SYSTEM->CurrentControlSet->Control->Nls->CodePage 检查 OEMCP 值。

change your system locale to English(United States), on windows 7 Regional Settings -> Administrative->Change System locale. also after do that you can check it in regedit value.
regedit->HKEY_LOCAL_MACHINE->SYSTEM->CurrentControlSet->Control->Nls->CodePage check OEMCP value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文