Hello. Is it possible to somehow get a list of databases available for connection, and not explicitly set the database name in the setDatabaseName () method? Roughly speaking, in order to display all available for connection in the combo box and choose from which one to which one to connect to?
- It depends on which DBMS you use. - maestro
- I use ms sql server - Kirill Razuvayev
- doc.qt.io/qt-5/qsqldatabase.html#connectionNames , or is something else meant? - Chorkov
- First you need to decide what it means "accessible to connect the database." - Sergey Gornostaev
- Suppose there are 3 databases working on the server simultaneously. You need to detect them all and add them to the list so that in the interface you can already choose which one to connect to and not write all connection parameters in the code with your hands - Kirill Razuvaev
|
2 answers
To do this, you need to work with the API of some DBMS and this will be your private solution.
And if you are talking about general functionality, then, in fact, in any way, Qt is no exception.
Here the principle is simple and is related to database security. The administrator has access to the DBMS, and the database administrator has access to a specific database (in general, they are different people).
For example, in such a way are organized DBMS on hosting servers. Otherwise, any new site could have access to the list of all databases managed by this DBMS, which, as you can guess, is undesirable.
- Understood thanks. So far, the usual connection is enough then - Kirill Razuvaev
|
Do you mean this?
select name from sys.databases; |