Subject Firebird over ODBC to .NET
Author peter_jacobi.rm
Dear all,

I tried a simple test program from
http://www.go-mono.com/odbc.html
(see below for complete source) to
test ODBC access to a Firebird DB from
C#.NET (yes, I'm aware that there is a
a native .NET driver).

I compiled and run using MONO 0.21 running on
WinNT4 SP6a.

I tested both the IB Phoenix and the XTG
ODBC drivers.

In both cases connection was successfull bad
data retrieval failed giving the error messages:

Unhandled Exception: System.NullReferenceException: A null value was
found where an object instance was required
in <0x00082> 00 System.Data.Odbc.OdbcDataReader:ColIndex (string)
in <0x0008a> 00 System.Data.Odbc.OdbcDataReader:get_Item (string)
in <0x00113> 00 .Test:Main (string[])

I assume it is most likely that the problem is with MONO,
but anyway I want to mention it here. And perhaps someone
can test the simple program with MSFT .NET?

The C# source code:

using System;
using System.Data;
using System.Data.Odbc;

public class Test
{
public static void Main(string[] args)
{
string connectionString =
"DSN=Employee;" +
"UID=sysdba;" +
"PWD=masterkey";
IDbConnection dbcon =
new OdbcConnection(connectionString);
dbcon.Open();
IDbCommand dbcmd = dbcon.CreateCommand();
dbcmd.CommandText =
"SELECT first_name, last_name FROM employee";
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
string FirstName = reader["FIRST_NAME"].ToString();
string LastName = reader["LAST_NAME"].ToString();
Console.WriteLine("Name: " + FirstName + " " + LastName);
}
// clean up
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
}