[Mono-list] Mono and ODBC

José Alejandro Manuel García al3jandro.mg at gmail.com
Mon Apr 17 17:45:46 EDT 2006


Hi, I like to know what is ODBC status in Mono, I have a code of
example that I copied of MSDN website, is the follwing:

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

 public class Test
 {
    public static void Main()
    {
		string connectionString = "DSN=rsur";
		OdbcConnection myConn = new OdbcConnection(connectionString);
		string sql = "SELECT Matricula, Nombre FROM Alumnos";
   		OdbcCommand myCommand = new OdbcCommand(sql, myConn);
   		myConn.Open();
		
		Console.WriteLine("Execute sentence ...");
		OdbcDataReader myReader = myCommand.ExecuteReader();
   		while (myReader.Read())
		{
       		Console.WriteLine(myReader.GetString(0) + ", " +
myReader.GetString(1));
   	      }

    		// always call Close when done with connection.
    	myReader.Close();
   		myConn.Close();	
    }
 }

The compilation is succesful, instruction is this: mcs
-r:System.Data.dll example.cs

Then when I run it shell shows this exception:

Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object
in <0x000a6> System.Data.Odbc.OdbcDataReader:GetPrimaryKeys
(System.String catalog, System.String schema, System.String table)
in <0x00b5e> System.Data.Odbc.OdbcDataReader:GetSchemaTable ()
in (wrapper remoting-invoke-with-check)
System.Data.Odbc.OdbcDataReader:GetSchemaTable ()
in <0x00094> System.Data.Odbc.OdbcDataReader:.ctor
(System.Data.Odbc.OdbcCommand command, CommandBehavior behavior)
in <0x00010> System.Data.Odbc.OdbcDataReader:.ctor
(System.Data.Odbc.OdbcCommand command, CommandBehavior behavior, Int32
recordAffected)
in (wrapper remoting-invoke-with-check)
System.Data.Odbc.OdbcDataReader:.ctor
(System.Data.Odbc.OdbcCommand,System.Data.CommandBehavior,int)

in <0x00034> System.Data.Odbc.OdbcCommand:ExecuteReader
(CommandBehavior behavior)
in <0x0000c> System.Data.Odbc.OdbcCommand:ExecuteReader ()
in (wrapper remoting-invoke-with-check)
System.Data.Odbc.OdbcCommand:ExecuteReader ()
in <0x000a3> Test:Main ()

I use Mono-1.1.14 in Windows XP Pro, Database is made in MS Access

--
José Alejandro Manuel García
Programador Junior -- G&W Systems Corp.
http://al3jandro.blogspot.com


More information about the Mono-list mailing list