Title: dbExpress ... Better than BDE
Question: One of the ways to set runtime database parameters to the TSQLConnection component in dbExpress
Answer:
It's been a long time since I wrote my previous article. I recently worked on a project with dbExpress and would like to share my experience with our community.
Since Borland is now giving more importance to dbExpress and trying to get rid of BDE in future releases, we used dbExpress in that project. I have seen a whole lot of threads discussing/comparing the features of dbExpress with BDE in our Borland newsgroups; it's really interesting.
Even though there are a lot of benefits using dbExpress, I liked the following features of dbExpress:
1. Changing between databases:
If you want your application to point to a new database, then all you need to do is to change the entries in the dbxconnections.ini file and in the code, you need to call the LoadParamsFromIniFile method. But you may need to set the following properties of the TSQLConnection component:
a. ConnectionName
b. GetDriverFunc
c. LibraryName and
d. VendorLib
I used a procedure like this:
Procedure Connect;
begin
SQLConnection1.ConnectionName := 'Oracle';
SQLConnection1.DriverName := 'Oracle';
SQLConnection1.GetDriverFunc := 'getSQLDriverORACLE';
SQLConnection1.VendorLib := 'OCI.DLL';
SQLConnection1.LoadParamsFromIniFile('dbxConnections.ini');
SQLConnection1.Open;
end;
You can get all those values as parameters to the application. Or the other option I would see is to add these properties as part of the dbxconnections.ini file and read it from there. Even though I have not tried this option, I hope this would work fine.
Another important thing to note is that if you are setting these properties at runtime, you need to make sure that the LoadParamsOnConnect property of TSQLConnection be false.
After setting all those parameters and setting the Connected property to True will establish a connection to the database. But for some reason, if you provide some wrong parameters and try to set the Connected property to True at runtime somehow passes. I heard that this is a bug in dbExpress and been fixed in Delphi 6. But I doubt it's been fixed in Delphi 6 since I tried with Delphi 6 only. Instead I used the ConnectionState property of the TSQLConnection component. It seems to work fine. Let me know if I'm wrong.
2. Easy Deployment - lightweight:
Deploying an dbExpress application requires the relevant database driver files and the dbxconnections.ini file. But for BDE applications, we need to install the BDE and create a relevant Aliases for the databases.
3. What I would like to know?
I have used BDE before and there is a session component available that you can attach to the database component but in dbExpress, I dont see such a component. Is there any way we can achieve the same with dbExpress component? Feel free to share your thoughts on this.
Thanks.
Magesh.