I had this module that handled the connection string that connect to my database:
Module DBCONNECTION
Public myGlobalConnectionString As String
Public Sub Main()
Dim sDataserver As String
Dim sDatabaseName As String
Dim sDatabaseConnection As String
Try
sDataserver = "localhost"
sDatabaseName = "Student"
sDatabaseConnection = ("Driver={MariaDB ODBC 3.1 Driver};SERVER=" & sDataserver & ";USER=root;PASSWORD=****;DATABASE=" & sDatabaseName & ";PORT=3306")
sDatabaseConnection = myGlobalConnectionString
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Module
and i had this class that will open and close the connection of myGlobalConnectionString
Public Shared Sub OpenDb()
Dim con = New OleDb.OleDbConnection
con.ConnectionString = myGlobalConnectionString
con.Open() // when it tried to open, the error appear
End Sub
Public Shared Sub CloseDb()
Dim con = New OleDb.OleDbConnection
If Not con Is Nothing Then
con.Close()
con = Nothing
End If
End Sub
and my form
Private Sub LoginForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim con As New clsDataQuery
con.OpenDb()
End Sub
I get this error
System.InvalidOperationException: 'The ConnectionString property has not been initialized.'
How do I fix this error?
question from:
https://stackoverflow.com/questions/66045784/how-to-connect-my-vb-net-project-to-mariadb-using-ado-net 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…