[Mono-list] Problems with ODBC connection.

beniniva@csr.unibo.it beniniva@csr.unibo.it
Wed, 10 Mar 2004 11:15:43 +0100


I've an ODBC connection test named TestODBC.cs 
(connecting to MySQL database with a connection string) that works correctly 
on Windows XP using Visual Studio.Net 2003, but not on Mono.



I compiled and ran TestODBC.cs, but threre are errors.


On Windows:


>mcs TestODBC.cs -r System.Data.dll

 Compilation succeeded



>mono TestODBC.exe



 Unhandled Exception: System.Data.Odbc.OdbcException: Error in SQLAllocHandle

 in <0x000bb> System.Data.Odbc.OdbcConnection:.ctor ()

 in <0x0000a> System.Data.Odbc.OdbcConnection:.ctor (string)

 in <0x0004d> (wrapper remoting-invoke-with-check)
System.Data.Odbc.OdbcConnection:.ctor (string)

 in <0x00066> TestODBC.Test:Main ()



On Linux (via UnixODBC)

# mcs TestODBC.cs  -r System.Data.dll
 Compilation succeeded

# mono TestODBC.exe
 
Unhandled Exception: System.DllNotFoundException: odbc32
in <0x0005c> (wrapper managed-to-native) System.Data.Odbc.libodbc:SQLAllocHandle
 (System.Data.Odbc.OdbcHandleType,intptr,intptr&)
in <0x00073> System.Data.Odbc.OdbcConnection:.ctor ()
in <0x0000a> System.Data.Odbc.OdbcConnection:.ctor (string)
in <0x00056> (wrapper remoting-invoke-with-check) System.Data.Odbc.OdbcConnectio
n:.ctor (string)
in <0x00069> TestODBC.Test:Main ()


######

TestODBC.cs

######


using System;

using System.Data;

using System.Data.Odbc;



namespace TestODBC 

{

	class Test 

	{

		public static void Main()

		{ 

			OdbcDataReader dbReader = null;

			OdbcConnection conn = null;

			

			conn = new OdbcConnection("DRIVER={MySQL ODBC 3.51
Driver};"+"SERVER=localhost;"+"DATABASE=db1;"+"UID=utente;"+"PASSWORD=utentepwd;");

			conn.Open();

			

			OdbcCommand rcmd = conn.CreateCommand();

			rcmd.CommandText="select * from Indirizzi";

			dbReader=rcmd.ExecuteReader();

				

			Console.WriteLine();

			for (int i=0; i<3; i++)

			{

				Console.Write("{0},{1}", dbReader.GetName(i), " ");

			}

			Console.WriteLine("\n{0}", " ");

				

			int Codice;

			string Nome;

			string Cognome;

					



			while (dbReader.Read())

			{

				Codice = dbReader.GetInt32(0);

				Nome = (string)dbReader.GetValue(1);

				Cognome= (string)dbReader["Cognome"];

				

					

				Console.WriteLine("{0}{1}{2}{3}{4}", Codice.ToString() ,"    " , Nome,"    "
, Cognome);

			}

			dbReader.Close();

			conn.Close();	

		}

	}

}
#####

Where is the error?



Could anybody help me?



Thanks,



Vale.