[Mono-dev] ODBC GetSchema failing

discofire discofire at aol.com
Mon Apr 27 21:42:48 UTC 2015


I have a very simple application that connects to an ODBC data source (MySQL
at the moment, but I plan on connecting to data sources without ADO.NET
drivers, and thus need ODBC support).  I am able to query the database
without any problems, and I can run GetSchema() in order to get a list of
valid collection names, however, when I attempt to run GetSchema("Tables")
or any other collection, I get what appears to be a recursive call from
GetSchema(string, string[]) and the program eventually crashes with a
StackOverflowException.

*Here is my code:*

 using System;
 using System.Data;
 using System.Data.Odbc;
 using System.Data.Common;
 
 public class Test
 {
    public static void Main(string[] args)
    {
       string connectionString =
"DRIVER={MySQL};SERVER=exagos01;PORT=3306;DATABASE=Northwind_Training;UID=root;PASSWORD=dba;OPTION=3";
       DbConnection dbcon;
       dbcon = new OdbcConnection(connectionString);
       dbcon.Open();

       DataTable dt = dbcon.GetSchema("Tables");
       //DataTable dt = dbcon.GetSchema();
       foreach(DataRow dr in dt.Rows) {
         for(int i=0; i<dt.Columns.Count; i++) {
           Console.Write(dr[dt.Columns[i].ColumnName]+"\t");
         }
         Console.WriteLine();
       }

       DbCommand dbcmd = dbcon.CreateCommand();
       string sql = "SELECT firstname, lastname FROM employees";
       dbcmd.CommandText = sql;
       IDataReader reader = dbcmd.ExecuteReader();
       while(reader.Read()) {
            string FirstName = (string) reader["firstname"];
            string LastName = (string) reader["lastname"];
            Console.WriteLine("Name: " +
                FirstName + " " + LastName);
       }
    }
 }


<b>And a small sample of the output (The actual output is thousands of
lines of the same error):*

  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string,string[]) <0x00033>
  at System.Data.Odbc.OdbcConnection.GetSchema (string) <0x0001a>
  at Test.Main (string[]) <0x00089>
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object
(object,intptr,intptr,intptr) <0xffffffff>



Any thoughts?  I haven't been successful in finding even a mention of this
problem online, and I haven't been able to come up with a reasonable
workaround... GetSchema is required (can't rely on PRAGMA statements since
the syntax can be different from one database to the next)




--
View this message in context: http://mono.1490590.n4.nabble.com/ODBC-GetSchema-failing-tp4665832.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list