Best Practice - db connectivity in multiple windows

Windows 10 Desktop App using MySQL (i.e. MariaDB) with two or more independent windows:

Is it better to have one top level database connection open, accessible by each window? Or should the connection be established at the local window level independently for each window? The user may have two or more windows open at a time or not.

For this design, I’d use one per window. It depends on the database type, but for MySQL, one each is appropriate.

OK, thanks.

The answer is it depends. Will things be going on in the background in each window without user interaction? Or does it depends on what the user is doing?

We tend to make a global database connection for desktop applications and then do a separate connections for each thread using the database. Window events fire on the main thread so I don’t see much advantage of separate db connections for each window, unless you’re doing something that’s ‘thread-like’ in each one using timers and such. And if you have things going on that take a really long time then perhaps you should be looking at threads with separate connections.

Just my two cents worth.

Thanks Bob.