Msg 6522, Level 16, State 1, Line 4 A .NET Framework error occurred during execution of user-defined routine or aggregate "GetDataSourceContents2": System.InvalidCastException: Unable to cast object of type 'SqlServerProject2.webservice.DataSourceDefinition' to type 'System.Collections.IEnumerable'. System.InvalidCastException: at SqlServerProject2.UserDefinedFunctions.GetDataSources2(String Datasourcename) .
I get the above error while running the clr function from the below vb.net assembly. Can someone help?
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