[Mono-list] Still problems with database access using ODBC

lunkwill at gmx.net lunkwill at gmx.net
Thu Jul 7 03:50:25 EDT 2005

Hi all!

Nearly 2 months ago I posted a bug (
http://bugzilla.ximian.com/show_bug.cgi?id=74917 ) about using SQL
parameters in ODBC queries.
In short: using OdbcParameter with int-parameters works; with char and
varchar-parameters it fails

As I got no anwers/solution so far, I just want to know 
a) if anybody else experiences these problems
b) if someone is working on the ODBC-code in general or concerning my

The bug report is a bit lengthy and originally refers to Mono 1.1.7. My
latest tests with Mono still have the same problem.
I was testing with 
a) Mono (SLES9)/unixODBC 2.2.11
b) Mono 1.1.8 Win Installer/ODBC
c) M$ .NET 1.1/ODBC

I have testet with Informix and FirebirdSQL which lead to different error
messages. The result is the same: it works with .NET and fails using Mono
Test case see below or in the mentioned bug report

Any help would be appreciated! Pls. send answers to the list.



My DB tables + contens:
SQL> show table t_odbc_test;
ID                              SMALLINT Not Null
LAST_NAME                       VARCHAR(20) Nullable
FIRST_NAME                      CHAR(20) Nullable
TESTINT                         INTEGER Nullable
  Primary key (ID)
SQL> select * from t_odbc_test;

     ID LAST_NAME            FIRST_NAME                TESTINT
======= ==================== ==================== ============

      1 Dent                 Arthur                         10
      2 Prefect              Ford                           20

My test program:

class MainClass
   public static void Main(string[] args)
      string dsn = args[0]; // the ODBC DSN
      string typ = args[1]; // varchar|char|int

      string DB_CONN = "DSN=" + dsn;

      Console.WriteLine("act. DSN:      " + DB_CONN);
      Console.WriteLine("act. OdbcType: " + typ);

      using (OdbcConnection conn = new OdbcConnection(DB_CONN)) {
         OdbcCommand cmdFail = conn.CreateCommand();
         cmdFail.CommandType = CommandType.Text;

         switch (typ) {
            case "varchar": // last_name is of type VarChar
               cmdFail.CommandText =
                  "SELECT * FROM t_odbc_test WHERE last_name=?";
OdbcType.VarChar,20).Value = "Perfect";
            case "char": // first_name is of type Char
               cmdFail.CommandText =
                  "SELECT * FROM t_odbc_test WHERE first_name=?";
OdbcType.Char,20).Value = "Ford%";
            case "int": // testint is of type Integer
               cmdFail.CommandText =
                  "SELECT * FROM t_odbc_test WHERE testint=?";
               cmdFail.Parameters.Add("@p1", OdbcType.Int).Value = 20;


         OdbcDataReader readerFail = cmdFail.ExecuteReader();

         while (readerFail.Read())
            Console.WriteLine("--> " + readerFail["LAST_NAME"]);


Weitersagen: GMX DSL-Flatrates mit Tempo-Garantie!
Ab 4,99 Euro/Monat: http://www.gmx.net/de/go/dsl

More information about the Mono-list mailing list