vb.net服务器连接过载

问题描述:

我试图运行此代码,但它显示错误“重载解析失败”。vb.net服务器连接过载

Conn = New OleDbConnection(ConnectionString)  
Dim serverConn As New Server(New ServerConnection(Conn)) 

以下是完整的错误:

Overload resolution failed because no accessible 'New' can be called with these arguments: 
'Public Sub New(serverInstance As String)': Value of type 'System.Data.OleDb.OleDbConnection' cannot be converted to 'String'. 
'Public Sub New(sqlConnection As System.Data.SqlClient.SqlConnection)': Value of type 'System.Data.OleDb.OleDbConnection' cannot be converted to 'System.Data.SqlClient.SqlConnection'. 
'Public Sub New(sci As Microsoft.SqlServer.Management.Common.SqlConnectionInfo)': Value of type 'System.Data.OleDb.OleDbConnection' cannot be converted to 'Microsoft.SqlServer.Management.Common.SqlConnectionInfo'. 

如果你想管理的MS SQL Server,你要SqlConnection,而不是一个普通的OleDbConnection

或者将OleDbConnection替换为SqlConnection,或者将ConnectionString右移New Server(),而不先实例化显式连接。