errors: "Missing DriverName property" and "Unable to load

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for MySQL in Delphi and C++Builder
Post Reply
neko_whisker
Posts: 1
Joined: Thu 15 Sep 2011 08:02

errors: "Missing DriverName property" and "Unable to load

Post by neko_whisker » Thu 15 Sep 2011 08:59

Hi All I have problem accessing the local database in the simple way.
The program just read register and then test whether the DB can be accessed.
I have two dll in my development folder along with the program I built.
I also have path directed to dll files used in Borland Delphi program

I am using WinXP, MySQL 5 and DBExpress.

But the problem is that it gives two errors:
So here it goes...
1) "Missing DriverName property"

I would not do 2) but because of 1) so I have to do 2) in add SQLConnection in order to test

2) "Unable to load libmySQL.dll"

Here's the code
{code}
unit testDB_DSN;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ColorButton, Registry, checkDSN_DB, DBXpress, DB,
SqlExpr;

type
TForm1 = class(TForm)
edit_DSN: TEdit;
btn_DSN: TColorButton;
btn_Stop: TColorButton;
SQLConnection1: TSQLConnection;
procedure btn_DSNClick(Sender: TObject);
procedure btn_StopClick(Sender: TObject);
//procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }

end;

var
Form1: TForm1;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
edit_DSN.SetFocus;
end;

procedure TForm1.btn_DSNClick(Sender: TObject);
var name_DSN, source_key1, source_key2, value_DATABASE, value_SERVER : string;
checkDBConnect : integer;
regA : TRegistry;

begin
source_key1 := '\SOFTWARE\ODBC\ODBC.INI\;
name_DSN := edit_DSN.Text;
source_key2 := source_key1 + name_DSN;
regA := TRegistry.Create;// create an TRegistry object before reading
regA.RootKey := HKEY_LOCAL_MACHINE;// That's where information about DSN are located.


//Test the working of DSN in registry
if regA.OpenKey(source_key2, false)then
begin
value_DATABASE := regA.ReadString('DATABASE'); //read the string of the DATABASE key.
value_SERVER := regA.ReadString('SERVER'); //read the string of the SERVER key.
value_DRV := regA.ReadString('DRIVER'); //read the string of the DRIVER key.

//showmessage('Database = '+value_DATABASE+' and '+'Server = '+value_SERVER);
regA.CloseKey; //Close the key after use.

//Test the working of connecttion to DB
checkDBConnect := testDSNDB(value_DATABASE, value_SERVER, value_DRV);
if(checkDBConnect = 0) then
showMessage('Successful! The DSN '+ name_DSN +' is correct and able to connect to '+ value_DATABASE +' @ '+value_SERVER+' Server.')
else
showMessage('DB does not exist for DSN '+ name_DSN+'.');
end
else
//failed: 'DSN '+ name of DSN + ' does not exist or might have been wrongly spelt.'
ShowMessage('DSN '''+name_DSN + ''' does not exist or might have been wrongly spelt.');
begin
regA.Free;
edit_DSN.Clear();
edit_DSN.SetFocus;
// set this control in focus after clearing all the input
//so that it can be entered immediately.
end;
end;

procedure TForm1.btn_StopClick(Sender: TObject);
begin
close; // Use this "Close" command to terminate the running of the program.
end;

end.

{code}



{code}
unit checkDSN_DB;

interface

uses SqlExpr, DB;

//declaration in the interface
function testDSNDB(str_DB, str_SVR, str_DRV : string): integer;
//add this function under interface so that this function can be seen by other units.

implementation

function testDSNDB(str_DB, str_SVR, st_DRV : string): integer;
var db_Connect : TSQLConnection;
begin

db_Connect := TSQLConnection.Create(nil);

try
db_Connect.Params.Values['DriverName']:=str_DRV;//Driver
db_Connect.Params.Values['User_Name'] := '';//mk10basicjig1
db_Connect.Params.Values['Password'] := '';//basicjig1
db_Connect.Params.Values['HostName'] := str_SVR;//HostName
db_Connect.Params.Values['Database'] := str_DB;//DatabaseName
db_Connect.Params.Values['BlobSize'] := '-1';
db_Connect.Params.Values['LocaleCode'] := '0000';
db_Connect.Open;

result := 0;
except
result :=1;
end;
db_Connect.Free;
end;
end.

{code}

Pls advise the solution
Thank you
Clement

AndreyZ

Post by AndreyZ » Thu 15 Sep 2011 13:50

Hello,

1. This error means that you didn't set the TSQLConnection.DriverName property.
2. This error means that there is no libmysql.dll in the System32 directory. You should place libmysql.dll to the C:\Windows\System32 directory.

Here are two code examples that demonstrate the correct ways to establish connection to MySQL server:
1. using libmysql.dll :

Code: Select all

SQLConnection1.DriverName := 'Devart MySQL';
SQLConnection1.ConnectionName := 'DevartMySQL';
SQLConnection1.GetDriverFunc := 'getSQLDriverMySQL';
SQLConnection1.LibraryName := 'dbexpmda.dll'; // or dbexpmda30.dll, or dbexpmda40.dll (depends on your IDE)
SQLConnection1.VendorLib := 'libmysql.dll';
SQLConnection1.LoginPrompt := False;
SQLConnection1.Params.Values['HostName'] := 'hostname';
SQLConnection1.Params.Values['Database'] := 'database';
SQLConnection1.Params.Values['User_Name'] := 'username';
SQLConnection1.Params.Values['Password'] := 'password';
SQLConnection1.Open;
2. without using libmysql.dll , direct connection:

Code: Select all

SQLConnection1.DriverName := 'Devart MySQL Direct';
SQLConnection1.ConnectionName := 'DevartMySQLDirect';
SQLConnection1.GetDriverFunc := 'getSQLDriverMySQLDirect';
SQLConnection1.LibraryName := 'dbexpmda.dll'; // or dbexpmda30.dll, or dbexpmda40.dll (depends on your IDE)
SQLConnection1.VendorLib := 'not used';
SQLConnection1.LoginPrompt := False;
SQLConnection1.Params.Values['HostName'] := 'hostname';
SQLConnection1.Params.Values['Database'] := 'database';
SQLConnection1.Params.Values['User_Name'] := 'username';
SQLConnection1.Params.Values['Password'] := 'password';
SQLConnection1.Open;
It's better to use direct connection, because in this case you don't need libmysql.dll. Also you will have better performance.

Post Reply