我想使用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;
}
}
}
答案 0 :(得分:3)
FirebirdClient
不适用于InterBase。这是Firebird。您需要为InterBase使用ADO.NET提供程序。