vb.net服务器连接重载

时间:2012-02-26 11:25:36

标签: sql vb.net smo

我试图运行此代码,但它显示错误"重载解析失败"。

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'.   

1 个答案:

答案 0 :(得分:0)

如果要管理MS SQL Server,则需要SqlConnection,而不是通用OleDbConnection

OleDbConnection替换为SqlConnection,或将ConnectionString权限传递给New Server(),而不首先实例化显式连接。