© 2019 BY マルハチITサービス PROUDLY CREATED WITH Wix.com​

  • Kawahara

IBM.Data.DB2.iSeriesの検証(2)

参照を追加したらフォームにdataGridView1とbutton1を追加。


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using IBM.Data.DB2.iSeries;

namespace DB2Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            const string CN_STRING_DB2 = "DataSource=(ホスト名);USERID=(ユーザー名);PASSWORD=(パスワード);";

            StringBuilder sqlbldr = new StringBuilder();
            sqlbldr.AppendLine("select");
            sqlbldr.AppendLine("    COUNT(*)");
            sqlbldr.AppendLine("FROM");
            sqlbldr.AppendLine("    TESTLIB.TEST");


            using (iDB2Connection cn = new iDB2Connection(CN_STRING_DB2))
            {
                cn.Open();
                iDB2Command cmd = cn.CreateCommand();
                cmd.CommandText = sqlbldr.ToString();
                using (iDB2DataAdapter da = new iDB2DataAdapter(cmd))
                {
                    DataTable dt = new DataTable();
                    dt.Locale = System.Globalization.CultureInfo.InvariantCulture;
                    da.Fill(dt);

                    dataGridView1.DataSource = dt;
                }
            }
        }
    }
}

その後、iSeriesナビゲーターがインストールされていないXP上で実行すると・・・


だめでした。エラーメッセージのせておきます。

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text ************** System.TypeInitializationException: The type initializer for ‘IBM.Data.DB2.iSeries.iDB2Constants’ threw an exception. —> An unexpected exception occurred. Type: System.DllNotFoundException, Message: Unable to load DLL ‘cwbdc.dll’: 指定されたモジュールが見つかりません。 (Exception from HRESULT: 0x8007007E). — End of inner exception stack trace — at IBM.Data.DB2.iSeries.iDB2Connection.InitializeDefaultProperties() at IBM.Data.DB2.iSeries.iDB2Connection..ctor(String connectionString) at DB2Test.Form1.button1_Click(Object sender, EventArgs e) in D:Visual Studio 2005ProjectsDB2TestDB2TestForm1.cs:line 30 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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies ************** mscorlib Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400) CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll —————————————- DB2Test Assembly Version: 1.0.0.0 Win32 Version: 1.0.0.0 CodeBase: file:///C:/temp/DB2Test/DB2Test.exe —————————————- System.Windows.Forms Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400) CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll —————————————- System Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400) CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll —————————————- System.Drawing Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400) CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll —————————————- IBM.Data.DB2.iSeries Assembly Version: 10.0.0.0 Win32 Version: 11.0.9.1 CodeBase: file:///C:/temp/DB2Test/IBM.Data.DB2.iSeries.DLL —————————————- System.Data Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400) CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll —————————————- System.Xml Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400) CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll —————————————-

************** JIT Debugging ************** To enable just-in-time (JIT) debugging, the .config file for this application or computer (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled.

For example:

<configuration> <system.windows.forms jitDebugging=”true” /> </configuration>

When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the computer rather than be handled by this dialog box.

#AS400 #DB2

0回の閲覧