Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2002
    Posts
    2

    Unanswered: Connect to mysql with ado.net

    I've managed to get a OBDC connection with .net and mysql but it blows up when I try and do anything.

    Here is the code
    .
    using Microsoft.Data.Odbc;
    .
    .
    private void button1_Click(object sender, System.EventArgs e) {
    try {
    string connect = "DSN=TileDSN;";
    string command = "select * from sound_lookup";
    OdbcConnection con = new OdbcConnection(connect);
    con.Open();
    OdbcDataAdapter dAdpt = new OdbcDataAdapter(command,con);
    DataSet Data = new DataSet();
    dAdpt.Fill(Data,"Sound_Lookup");
    con.Close();
    }
    catch (Exception ex) {
    MessageBox.Show(ex.Message +"\n" + ex.Source+ "\n" + ex.ToString());
    }
    }

    And here is the Exception is throws

    Object reference not set to an instance of an object.
    Microsoft.Data.Odbc
    System.NullReferenceException: Object reference not set to an instance of an object.
    at System.Data.Common.Odbc32.SQLExecDirectW(IntPtr StatementHandle, String StatementText, Int32 TextLength)
    at Microsoft.Data.Odbc.OdbcCommand.ExecuteReaderObjec t(CommandBehavior behavior, String method)
    at Microsoft.Data.Odbc.OdbcCommand.ExecuteReader(Comm andBehavior behavior)
    at Microsoft.Data.Odbc.OdbcCommand.System.Data.IDbCom mand.ExecuteReader(CommandBehavior behavior)
    at System.Data.Common.DbDataAdapter.Fill(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
    at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
    at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
    at WindowsApplication2.Form1.button1_Click(Object sender, EventArgs e) in d:\projects\windowsapplication2\form1.cs:line 110

    It blows up on the fill statement. Evidently something isn't getting set, but what I have no idea as to what.

    Thanks

    Harvey Morris

  2. #2
    Join Date
    Mar 2002
    Posts
    2
    As usual I figure it out 30 minutes after I start posting questions.

    The last problem, of many, was I needed to update the myODBC drivers from 3.51.01 to 3.51.02

    Wish there was SOMETHING on the mysql webpage letting you know they had been updated.

    Anwyay its working great now.



    "Just say NO to recordsets"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •