MBS plugin, error after second query to same SQLDatabaseMBS

Hi, I’m trying to use the MBS plugin (because Xojo’s MySQL plugin continues to cause my web application to freeze, even on Xojo version 2026r1.2).
I’m trying to use the following code, but errors are raised even when I run simple queries.

Sub Pressed()
  Try
    Dim dd As New SQLDatabaseMBS
    dd.DatabaseName="mysql:127.0.0.1,3306@dbxy"
    dd.UserName="userzz"
    dd.Password="pswzz"
    
    Dim f As  FolderItem= New FolderItem("C:\Program Files\MySQL\MySQL Server 5.7\lib\libmysql.dll")
    dd.SetFileOption SQLConnectionMBS.kOptionLibraryMySQL, f
    
    Dim r As RowSet
    r=db.SelectSQL("Select *  from allegati limit 100")
    
    Dim r1 As RowSet
    r1=db.SelectSQL("Select *  from allegati limit 100")
    
    
  Catch err As RuntimeException
    err=err
  End Try 
  
End Sub

after the second query and when the second rowset (r1) is created, an error is generated

Does anyone know if there is a solution? thanks a lot.

where is the call for db.connect to connect to the database?

And if the DLL requires other DLLs in the same folder, you may also call

call SetDllDirectory("C:\Program Files\MySQL\MySQL Server 5.7\lib")

before doing the connect, so Windows knows where to find DLLs.

In a webCommandButton on a webPage

It looks like you’re initializing a new connection here named dd but not actually calling dd.Connect anywhere in this code. Then you are doing your actual queries with a different connection that is named db

I’d recommend calling dd.Connect and then changing your queries to r = dd.SelectSQL("Select * from allegati limit 100") to see if that works.

2 Likes

In the first version, I used a database variable, creating it as a property of Windows1. Then, to simplify the code, I introduced a variable within the Button3 button code.

Now I’ve changed the rowset creation to point to dbButton3, but the error persists and is the same.

Christian, I don’t understand how to use this code
call SetDllDirectory("C:\Program Files\MySQL\MySQL Server 5.7\lib")
I’m trying to insert it, but xojo tells me there’s an error.

Do you have a dll at that location? I would find that rather unlikely if you use Xojo Web.

Sorry, missing class name:

call SQLGlobalsMBS.SetDllDirectory("C:\Program Files\MySQL\MySQL Server 5.7\lib")

You may keep the connection around in a property. So you don’t need to connect each time someone presses a button.

What does happen after connect? Does it connect?

1 Like

as you can see the dll exists

now, i’m tring the using of MBS sql plugling (here i use a sample code on xojo desktop project for simplifing the code) and if it works i will use MBS sql pugin as substitute of XOJO Mysql plugin beacuse xojo mysql plugin freeze my actual webapp.

A fundamental question for everyone here:
Is it okay to use a single database object for multiple SQL queries simultaneously?

Or would it be safer to use a separate database object for each query?

1 Like

ok, i have made changes in the code but i obtain Same error

the first query works fine

r=dbButton3.SelectSQL("Select *  from allegati limit 100")

at the second query

r1=dbButton3.SelectSQL("Select *  from allegati limit 100")

it is raised the error

I really hope so, because if I had to open a new database connection for each query, in complex code, I would crash the database server (DOS).

Really? We use an application built with Xojo and the MySQL Community Server, establishing—with up to 10 concurrent users—as many as 40 simultaneous connections per user to one or more servers. Without any issues. For years.

I use a separate connection for every (concurrent) query, and I establish a new connection each time using ‘Connect’—specifically to ensure that the server is indeed (still) connected and that no queries interfere with one another.

And you should check your database access for errors using a try-catch block.

What follows is actually not recommended—an UnhandledException handler within the App object would be a better choice.

What version of XoJo are you using?

In my case, with the application developed with XoJo 2019 R3.2, I have no problems .ù

Since XoJo 2024 R4.2, my web app that uses a MyQSQL connection has been crashing. It freezes randomly without generating errors, but it no longer responds to requests and remains in the background.

Currently, we are using Xojo 2025.2. However, since around 2015, we have consistently developed the app using the latest version of Xojo (though the most recent price increase has deterred us from continuing to purchase every new version sight unseen…).

Looks like you run multiple record/row sets, so you may need to tell MySQL that you like to have this:

db.Option("CLIENT_MULTI_STATEMENTS") = "true"
db.Option("CLIENT_MULTI_RESULTS") = "true"

set before connect. Does it help?
Otherwise you may need to set the rowset to nil to release it.

if i use DatabaseException the error is intercepted from ide

In the case of the MBS Plugin, you will likely need to use the following:

Catch err As SQLErrorExceptionMBS
1 Like

no, same error

i have added your code