working in vs2022
loads the DB names into an array
uses some kind of ADO, I think
It may also work with ADO.NET
Uses showdatabases command to the server
I found no good examples on the web, so here is a working one
Code:
Private Sub COMBOBOXLOAD()
On Error GoTo errhandler
'connect and load combobox with database names
'construct a connection string from listed text in the boxes
'leave it here this will be overwriten??
provider1 = "Provider=" & _Text1_0.Text & ";"
driver1 = "DRIVER=" & _Text1_1.Text & ";"
host1 = "SERVER=" & _Text1_2.Text & ";"
dbname1 = "DATABASE=" & Combo1.Text & ";"
user1 = "UID=" & _Text1_4.Text & ";"
pass1 = "PASSWORD=" & _Text1_5.Text & ";"
port1 = "PORT=" & _Text1_6.Text & ";"
opt1 = "Option=" & _Text1_7.Text & ";"
frmlogonConnectstring = provider1 & driver1 & dbname1 & host1 & user1 & pass1 & port1 & opt1
Dim Con1 As New ADODB.Connection
Con1.ConnectionString = frmlogonConnectstring
Con1.Open()
Combo1.Items.Clear()
Dim values As Object, trs As Object
'Con1.Execute("use information_schema")
'Dim sql As String = "select distinct table_schema from information_schema.tables"
Dim sql As String = "show databases"
trs = Con1.Execute(sql)
' Load the values into a variant object array.
values = trs.GetRows
trs.Close()
'? values(0, 1) "bigdb"
'? values(0, 7) "testspecialchars"
Dim numcols As Short = UBound(values, 1)
Dim numrows As Short = UBound(values, 2)
Xx = 1
Do Until Xx > numrows
'exclude server configuration db names from loading into a combobox
If values(0, Xx) <> "mysql" And values(0, Xx) <> "test" And values(0, Xx) <> "information_schema" And values(0, Xx) <> "sys" And values(0, Xx) <> "performance_schema" Then
Combo1.Items.Add(values(0, Xx))
End If
Xx = Xx + 1
Loop
Con1.Close()
ToolStripStatusLabel1.Text = _Text1_2.Text & " Server Connected Successfully"
ToolStripStatusLabel1.ForeColor = Color.Green
Exit Sub
ErrHandler:
ToolStripStatusLabel1.Text = _Text1_2.Text & " Server Not Connected"
ToolStripStatusLabel1.ForeColor = Color.Red
'con could not open
MsgBox(Err.Description & vbCrLf & vbCrLf & "Check connection settings")
End Sub