1

披露,我对 VB.net 比较陌生,但一般不会编程。

问题:我创建了一个使用 MySql 连接器连接到数据库的程序。一切都很好。昨天我决定使用 My.Settings 变量来存储一些登录信息。一旦我这样做了,我的数据库连接就会抛出这个错误......

'在 MySql.Data.dll 中发生'System.TypeInitializationException' 类型的异常,但未在用户代码中处理'

我想,我一定是做错了什么,所以我回滚到我的工作程序,测试它,它仍然有效。我继续添加 My.Settings 变量(没有代码更改),然后进行了测试运行,果然错误消息回来了。

有谁知道为什么会发生这种情况?任何想法都非常感谢。

我的系统上的相关信息。

  • MySql.Data.dll V8.0.28.0
  • Visual Studio 2022 V17.1.0
  • 语言是 Visual Basic

根据 nbk 的请求添加代码

Imports MySql.Data.MySqlClient

公开课形式1

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

结束类

在我添加 My.Settings 变量之前,上述方法工作正常。上面的代码没有变化。添加代码后运行它时,我开始收到错误消息。

完整的错误信息如下...

System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.

---> System.TypeInitializationException:'MySql.Data.MySqlClient.MySqlConfiguration' 的类型初始化程序引发了异常。---> System.Configuration.ConfigurationErrorsException:配置系统初始化失败---> System.Configuration.ConfigurationErrorsException:无法识别的配置部分system.diagnostics。(G:\WORK_IN_PROGRESS\VisualStudio2022_Programs\ExampleProject\bin\Debug\net6.0-windows\ExampleProject.dll.config 第 8 行)在 System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) 在 System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors) 在 System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors() 在 System.Configuration.ClientConfigurationSystem。

我添加的 My.Settings 变量

4

0 回答 0