#1 2015-09-21 15:44:38

erick
Member
Registered: 2015-09-09
Posts: 155

MySQL - ODBC or OLE, neither work for me

Hi, I'm having trouble connecting to MySQL through either ODBC or OLE.  I've installed the 64 bit drivers for both, and did the ODBC and OLE 'Test Connection' Successfully.

I've compiled SynDBEdit 64 bit and also tried my source code below.  I think I'm just entering a wrong field somewhere, but don't know where.   Examples on this board seem ancient because they generate compiler errors, so I think the syntax may have changed in the last year.

var
  MySQL: TOLEDBODBCSQLConnectionProperties;
  Conn: TSQLDBConnection;
  Query: TSQLDBStatement;
  F: TFileStream;
  password: RawUTF8;

begin

  // Model := CreateSampleModels;

  write('PASSWORD: ');
  readln(password);

//  MySQL := TOLEDBODBCSQLConnectionProperties.Create('mysql.1', 'localhost',
//    'cecs', 'root', StrToUTF8(password));
  MySQL := TOLEDBODBCSQLConnectionProperties.Create('MSDASQL.1','localhost', 'cecs', 'root', StrToUTF8(password));
  try
    Conn := MySQL.NewConnection;
    try
      Query := Conn.NewStatement;
      try
        Query.Execute('select * from employer', True, []);
        // select * from cecs.employer
// It FAILS at Query above with error: Unspecified Error [Microsoft][ODBC Driver Manager] Data Source Name not found and no specififed default driver


        F := TFileStream.Create('result.json', fmCreate);
        try
          Query.FetchAllToJSON(F, True);
        finally
          F.Free;
        end;
      finally
        Query.Free;
      end;
    finally
      Conn.Free;
    end;
  finally
    MySQL.Free;
  end;
  Database.Free;
  Model.Free;

I've tried changing the first argument of ..connectionproperties to 'MySQL ODBC 3.5 Unicode Driver' and other things, but the error never budges.
I've tried creating named user DSNs, named System DSNs, no change.

I've hacked at this for hours, so I'm asking for help.


Any hints on how to get a wor

Last edited by erick (2015-09-21 15:50:41)

Offline

#2 2015-09-21 15:59:10

erick
Member
Registered: 2015-09-09
Posts: 155

Re: MySQL - ODBC or OLE, neither work for me

A collegue of mine figured it out for me, so I'm documenting for those who follow me.

You enter:

  pseudoname := 'mysql.3';
  MySQL := TOLEDBODBCSQLConnectionProperties.Create( pseudoname, pseudoname, '', 'UseridBlah', 'passwordDooHicky');

Then, as long as you have no mismatch between the driver bitness (32 versus 64), it works.

Thanks

Offline

#3 2015-09-21 17:37:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,664
Website

Re: MySQL - ODBC or OLE, neither work for me

Yes, with ODBC, one of the option is to use a defined connection.

But 32 bit connections should match 32 bit apps.
And 64 bit connections should match 64 bit apps.

Offline

Board footer

Powered by FluxBB