c# IDbConnection FbConnection失败.索引超出范围



我想使用c#和Firebird客户端连接到本地网络中的Interbase Server。我尝试了很多不同的例子,但都失败了。最后我找到了这个页面http://www.mono-project.com/Firebird_Interbase,所以我基于这个例子编写了代码。

当我调用这个函数时,它返回错误:
Index is out of Range... (via MessageBox.Show(e.Message);)

我知道,整个代码是不干净的,但我想张贴完整的类,我修复其他错误以后。

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using FirebirdSql.Data.FirebirdClient;
namespace IBcon
{
    class interbase
    {
        public DataGridView testbla()
        {
            string connectionString =
            "Database=C:\data\DB.GDB;" +
            "User=SYSDBA;" + "Password=masterkey;" +
            "Dialect=3;" + "Server=192.168.1.15";
            IDbConnection dbcon = new  (connectionString);
            DataGridView dgv = new DataGridView();
            try
            {
                dbcon.Open();  <-- Error!
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return dgv;
            }
            IDbCommand dbcmd = dbcon.CreateCommand();
            string sql = "SELECT * FROM TABLE";
            dbcmd.CommandText = sql;
            IDataReader reader = dbcmd.ExecuteReader();
            dgv.DataSource = reader;
            DataSet ds = new DataSet();
            DataTable dt = new DataTable("TABLE");
            ds.Tables.Add(dt);
            ds.Load(reader, LoadOption.PreserveChanges, ds.Tables[0]);
            dgv.DataSource = ds.Tables[0];
            // clean up 
            reader.Close();
            reader = null;
            dbcmd.Dispose();
            dbcmd = null;
            dbcon.Close();
            dbcon = null;

            return dgv;
        }
    }
}

FirebirdClient不能与InterBase一起工作。这是给火鸟的。您需要使用ADO。

最新更新