[Mono-dev] Problem with national character set on ODBC connection

Mads Bondo Dydensborg mbd at dbc.dk
Mon Feb 18 04:02:58 EST 2008


onsdag 13 Februar 2008 skrev Torello Querci:
> Hi to all .....
> 
> I try to make an ODBC connection on windows environment.
> Using normal ascii character that code work fine, but if there is some
> national character, the result is wrong.

Hi Torello

I have run into a similar problem in the past, please see my mail to this list 
at
http://lists.ximian.com/pipermail/mono-devel-list/2007-July/024067.html

However, I did have the problem in all cases.

No solution was ever forthcoming. We are currently using my patch, but plan on 
moving away from mono's ODBC in the future.

Regards

Mads



> The result is wrong only if I make a bundle, not if I use mono
> <program_name.exe> or if I use .NET.
> I tried both the 1.2.6 and the 1.9 preview and the result is the same.
> 
> Is there a bug or I wrong something when generate the bundle
> 
> To generate the bundle I simply use this command:
> mkbundle2 --deps -o odbx2xml.exe program.exe
> 
> 
> Best Regards, Torello.
> 
> The testing database is an access file with one table named "users"
> with 3 column: name, surname, description with only one row ....
> 
> Here you can find the code:
> ------------------------------------------------------------------------------
> using System;
> using System.Collections;
> using System.Collections.Generic;
> using System.Text;
> using System.Data.Odbc;
> 
> namespace test_odbc
> {
>     class testOdbc : IDisposable
>     {
>         private System.Data.Odbc.OdbcConnection connection = null;
> 
>         public testOdbc(string connectionString)
>         {
>             connection=new OdbcConnection(connectionString);
>             try
>             {
>                 connection.Open();
>             }
>             catch (Exception ex)
>             {
>                 connection = null;
>                 System.Console.Out.WriteLine("Exception opening the
> database connection: " + ex.Message);
>             }
> 
>             return;
>         }
> 
>         public System.Data.Common.DbDataReader getRawData(string sqlQuery)
>         {
>             System.Data.Odbc.OdbcCommand command=connection.CreateCommand();
>             command.CommandText = sqlQuery;
>             command.CommandType = System.Data.CommandType.Text;
>             OdbcDataReader reader = command.ExecuteReader();
> 
>             return reader;
>         }
> 
>         public System.Collections.ArrayList
> getListOfFields(System.Data.Common.DbDataReader reader)
>         {
>             ArrayList fieldNameList = new ArrayList();
>             System.Data.DataTable dataTable = reader.GetSchemaTable();
>             foreach (System.Data.DataRow row in dataTable.Rows)
>             {
>                 if (!fieldNameList.Contains(row["Co6lumnName"].ToString())) 
{
>                     fieldNameList.Add(row["ColumnName"].ToString());
>                 }
>             }
>             dataTable.Dispose();
> 
>             return fieldNameList;
>         }
> 
>         public void Dispose()
>         {
>             if (connection != null)
>             {
>                 connection.Close();
>             }
> 
>         }
> 
>         static void Main(string[] args)
>         {
>             testOdbc odbc = new testOdbc("Dsn=test");
>             System.Data.Common.DbDataReader reader =
> odbc.getRawData("select * from users");
>             while (reader.Read())
>             {
>                 for (int i = 0; i < reader.FieldCount; i++)
>                 {
>                     object obj = reader.GetValue(i);
>                     System.Console.Out.WriteLine("column " + i + "
> data: " + reader.GetValue(i).ToString());
>                 }
>                 System.Console.Out.WriteLine("-----");
>             }
>         }
>     }
> }
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
> 
> 



-- 
Med venlig hilsen/Regards

Systemudvikler/Systemsdeveloper cand.scient.dat, Ph.d., Mads Bondo Dydensborg
Dansk BiblioteksCenter A/S, Tempovej 7-11, 2750 Ballerup, Tlf. +45 44 86 77 34



More information about the Mono-devel-list mailing list