PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [WD20] How to make me sure to use the same DB connection?
[WD20] How to make me sure to use the same DB connection?
Iniciado por guest, 15,feb. 2016 17:27 - 4 respuestas
Publicado el 15,febrero 2016 - 17:27
Hi,

in my application I use queries created by WD Query Editor by HExecuteQuery, queries written in MySQL code by HExecuteSQLQuery and the functions HTransactionStart, HTransactionEnd and HTransactionCancel.

The application has many components using these queries and sharing an external variable (ExtDBConnection) to make sure to use the same connection...but it is not enough, in the MySQL log I see many connections opened by the app.

Do someone of you have a technique?

Dann
Publicado el 15,febrero 2016 - 18:01
The same for me. The main exe opens the connection "MyConnection" with HOpenConnection + HChangeConnection for all tables (*.* parameter), then queries in other components (wdk) called by the main exe sometimes open their own connection even if there is a HOpenConnection at the beginning to ensure the usage of a unique connection.

This is quite bad because so each client opens several connections to MySql for working.
For sure, if you open a transaction with a connection and then the query in the transaction start in another connection it's like having no transaction at all...
Publicado el 15,febrero 2016 - 20:48
HTransactionStart, HTransactionEnd and HTransactionCancel do not work with MySQL

You need to use something like//Open connection for transaction processing :mnSQLConnect = SQLConnect(:mxDBServer,:mxDBUser,:mxDBPassword,:mxDBDatabase,"MySQL") followed by:mbSQLTrnActive = SQLTransaction(sqlStart,:msConnection)
After Commit or Rollback you need to issue an SQLDisconnect() otherwise connections will remain open on the DB
Publicado el 16,febrero 2016 - 08:58
Hi DerekT,

The online Help teaches that HTransactionStart, HTransactionEnd and HTransactionCancel work with the Native Access for MySQL, in the matter of facts it calls the "BEGIN", "COMMIT" and "ROLLBACK" functions...but...on the wrong connection.

I've already evaluated to use the SQL functions of WinDev, but it implies to use only MySQL code and without analysis. It's the wrong road for me

Dann
Publicado el 16,febrero 2016 - 11:57
I found issues with HTransactionxxx functions in that it left open connections on MySQL.
The help says to use HTransactionStart(MyConnection) which I did but I found that the correspondingHTransactionEnd(MyConnection)at the end of the process did not close the connection - This was v19, not tried v20.

Interpretation of the Help I guess but my reading of SQLTransaction is different to yours.
The help states 'This function is the only SQL function that can be used with the HFSQL functions (to perform transactions on an external database handled by the HFSQL functions for example)'
So if you are using HAdd, HModify etc (I do) to MySQL via Native Access then this is the way to go.

As per my previous post using SQLConnect(),SQLTransaction(sqlStart),SQLTransaction(sqlCommit) and the all important SQLDisconnect() always clears the connection created for the transaction.
And of course the transaction is started on the correct DB connection.

Each to his own but it works for me.