无法转换类型' DataSourceDefinition'的对象输入' System.Collections.IEnumerable'

时间:2016-10-20 20:31:01

标签: vb.net

Ms 6522,Level 16,State 1,Line 4 执行用户定义的例程或聚合期间发生.NET Framework错误" GetDataSourceContents2": System.InvalidCastException:无法转换类型' SqlServerProject2.webservice.DataSourceDefinition'输入' System.Collections.IEnumerable'。 System.InvalidCastException:    at SqlServerProject2.UserDefinedFunctions.GetDataSources2(String Datasourcename)

从下面的vb.net程序集运行clr函数时出现上述错误。有人可以帮忙吗?

Imports System
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Imports SqlServerProject2.webservice
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Runtime.InteropServices

Partial Public Class UserDefinedFunctions

<SqlFunction(FillRowMethodName:="FillRow")> _
Public Shared Function GetDataSources2(ByVal Datasourcename As String) As IEnumerable

    Dim WS = New ReportingService2005
    WS.UseDefaultCredentials = True

    Dim DSContents As DataSourceDefinition = WS.GetDataSourceContents(Datasourcename)

    Return DSContents

End Function

Public Shared Sub FillRow(ByVal obj As Object, <Out()> ByRef ConnectString As SqlString)
    Dim DSContents As DataSourceDefinition = CType(obj, DataSourceDefinition)
    ConnectString = New SqlString(DSContents.ConnectString)
End Sub
End Class

0 个答案:

没有答案