1 year ago
#221551
waslost1
VB.Net Issue: After adding my.settings variables MySql Connector stops working
Disclosure, I am relatively new to VB.net but not programming in general.
Problem: I created a program that uses a MySql connector to connect to a database. Everything worked great. Yesterday I decided to use My.Settings variables to store some login information. As soon as I did this, My database connections throw this error....
'An exception of type 'System.TypeInitializationException' occurred in MySql.Data.dll but was not handled in user code'
I thought, I must have done something wrong, so I rolled back to my working program, tested it and it still worked. I proceeded to add My.Settings variables again (no code changes), then did a test run, and sure enough the error message came back.
Does anyone have a clue as to why this happens? Any thoughts are most appreciated.
Relevant Information on my system.
- MySql.Data.dll V8.0.28.0
- Visual Studio 2022 V17.1.0
- Language is Visual Basic
Adding Code per nbk's request
Imports MySql.Data.MySqlClient
Public Class Form1
Dim MySQLconn As MySqlConnection
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MySQLconn = New MySqlConnection()
MySQLconn.ConnectionString = "server=127.0.0.1;userid=Joe;password=abc123"
'Test connection
Try
MySQLconn.Open()
MsgBox("Connection to Database Suceeded")
Catch ex As Exception
MsgBox("Failed to Connect to Database" + ex.Message)
Debug.Print(ex.Message)
Finally
MySQLconn.Dispose()
End Try
End Sub
End Class
This above works fine until I add a My.Settings variable. No changes to above code. When I run it after adding code, I begin to get the error.
Full error message below...
System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.
---> System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.MySqlConfiguration' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section system.diagnostics. (G:\WORK_IN_PROGRESS\VisualStudio2022_Programs\ExampleProject\bin\Debug\net6.0-windows\ExampleProject.dll.config line 8) at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors) at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors() at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey) --- End of inner exception stack trace --- at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey) at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName) at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at MySql.Data.MySqlClient.MySqlConfiguration..cctor() --- End of inner exception stack trace --- at MySql.Data.MySqlClient.MySqlConfiguration.get_Settings() at MySql.Data.MySqlClient.Replication.ReplicationManager..cctor() --- End of inner exception stack trace --- at MySql.Data.MySqlClient.Replication.ReplicationManager.IsReplicationGroup(String groupName) at MySql.Data.MySqlClient.MySqlConnection.Open() at ExampleProject.Form1.Button1_Click(Object sender, EventArgs e) in G:\WORK_IN_PROGRESS\VisualStudio2022_Programs\ExampleProject\Form1.vb:line 14
mysql
connector
my.settings
0 Answers
Your Answer