[Mono-list] ODBC.NET Provider on Windows

Daniel Morgan danmorg@sc.rr.com
Fri, 11 Oct 2002 03:49:46 -0400


Rodrigo and Brian

I have tried to get the Odbc.net provider to use Microsoft Window's native
ODBC library which is odbc32.dll by changing the DllImport from "libodbc" to
"odbc32".  The library apparently loads,
but I don't know what the errors are for.

Any ideas?

This is the results I got:

DanielMorgan@DANPC ~/mono/mcs/class/System.Data/Test
$ mono OdbcTest.exe
ERROR: SQLAllocHandle: <528285696>
ERROR: SQLSetEnvAttr: <528285696>
ODBCInit Complete.
ERROR: SQLAllocHandle(hdbc): <528285696>
ERROR: SQLConnect: <65535>
ERROR: SQLAlloc(Prepare): <528351231>
ERROR: SQLPrepare: <528351230>
ERROR: SQLExecute: <528351230>
ERROR: SQLCancel: <528351230>

Unhandled Exception: System.NotImplementedException: The requested feature
is no
t yet implemented
in <0x0002b> 00 System.Data.Odbc.OdbcCommand:Dispose (bool)
in <0x00015> 00 System.ComponentModel.Component:Dispose ()
in <0x00174> 00 Test.OdbcTest.OdbcTest:Main (string[])

I have a ODBC.net test named OdbcTest.cs that works on Windows XP
using .NET 1.1 Beta, but not Mono:

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

namespace Test.OdbcTest
{
	class OdbcTest
	{
		[STAThread]
		static void Main(string[] args)
		{
			OdbcConnection dbcon = new OdbcConnection();
			// connection string to a Microsoft SQL Server 2000 database
			dbcon.ConnectionString =
				"DRIVER={SQL Server};" +
				"SERVER=(local);" +
				"Trusted_connection=true;" +
				"DATABASE=pubs;";

			dbcon.Open();

			OdbcCommand dbcmd = new OdbcCommand();
			dbcmd.Connection = dbcon;
			dbcmd.CommandType = CommandType.Text;
			dbcmd.CommandText = "SELECT lname FROM employee";

			OdbcDataReader reader;
			reader = (OdbcDataReader) dbcmd.ExecuteReader();

			while(reader.Read()) {
				Console.WriteLine("Last Name: " + reader[0].ToString());
			}
			reader.Close();
			dbcmd.Dispose();
			dbcon.Close();
		}
	}
}