创建对象时的类型初始值设定项异常

时间:2021-12-20 20:36:13

I am getting a "The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception." error. This happens on the line "Dim cn As New SqlClient.SqlConnection".

我得到一个“System.Data.SqlClient.SqlConnection的类型初始化器”引发异常。错误。这发生在“Dim cn As New SqlClient.SqlConnection”行上。

If I open a new project and create this line, it all works?? I am banging my head!!

如果我打开一个新项目并创建这一行,这一切都有效吗?我在敲我的头!

1 个解决方案

#1


0  

Is your line of code only Dim cn As New SqlClient.SqlConnection? When creating a new SqlClient.SqlConnection you need to specify a connection string, like so:

你的代码行只是Dim cn As New SqlClient.SqlConnection?在创建新的SqlClient.SqlConnection时,您需要指定一个连接字符串,如下所示:

Dim cn as New SqlClient.SqlConnection("my connection string here")

#1


0  

Is your line of code only Dim cn As New SqlClient.SqlConnection? When creating a new SqlClient.SqlConnection you need to specify a connection string, like so:

你的代码行只是Dim cn As New SqlClient.SqlConnection?在创建新的SqlClient.SqlConnection时,您需要指定一个连接字符串,如下所示:

Dim cn as New SqlClient.SqlConnection("my connection string here")