Getting error when trying to setItemDataSources method in sql reporting

Domanda Getting error when trying to setItemDataSources method in sql reporting

  • lunedì 18 giugno 2012 10:17
     
     

    Hi all,

    While publishing rld report on report server from my installer project all things works fine till rdl files have one data source. But SetItemDataSources method fails when it encounters rdl that have two shared datasources.

    Here is my code:

     Private Sub InstallRdlFiles()

            dataSourceFolder = "Shared Data Sources"
            Sam5DataSourceName = "skm5"
            skmAdminDataSourceName = "SkmAdmin"
            dataSourceLocation = "/Shared Data Sources"
            skm5DbName = "skm5"
            skmAdminDbName = "SkmAdmin"

            'Fetch the values passed from User Interface.
            Try
                sqlServerName = "chetuiwk188/sql2005"
                'sqlServerName = Me.Context.Parameters("SNAME")
            Catch ex As Exception

            End Try

            Try
                uid = "sa"
                'uid = Me.Context.Parameters("UID")
            Catch ex As Exception

            End Try

            Try
                pwd = "skm@123"
                'pwd = Me.Context.Parameters("PASSWORD")
            Catch ex As Exception

            End Try

            'Set Report Server Credential
            rs.Credentials = System.Net.CredentialCache.DefaultCredentials

            'Create Folder to store Report files
            rs.CreateFolder("skmRS", "/", Nothing)

            'Create Folder For Data Source
            rs.CreateFolder(dataSourceFolder, "/", Nothing)
            'Create Report using RDL doc that was in MSI

            ' Create SAM5 DataSource
            CreateSAMDataSource()

            'Create SAMAdmin DataSource
            CreateSAMAdminDataSource()

            Dim reportPath As String
            Dim mstrProgramFilesPath As String = System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
            finalPath = mstrProgramFilesPath + "\skm_5.1.3\skm-Rdl SetUp"
            Dim dInfo As New DirectoryInfo(finalPath)

            Dim referenceSetting As String


            Dim fiArr As FileInfo() = dInfo.GetFiles()
            For Each fri In fiArr
                If (fri.Extension = ".rdl") Then
                    reportPath = fri.Name
                    referenceSetting = "/skmRS/" + reportPath
                    CreateSamReportFiles(reportPath)
                End If
            Next fri

            For Each fri In fiArr
                If (fri.Extension = ".rdl") Then
                    reportPath = fri.Name
                    referenceSetting = "/SAMRS/" + reportPath
                    SetReportFileReference(referenceSetting)
                 
                    'End If

                End If
            Next fri

            
        End Sub

        Private Sub CreateSAMDataSource()
            Dim dSource As New DataSource()
            Dim dDefinition As New DataSourceDefinition()

            dSource.Item = dDefinition

            dDefinition.Extension = "SQL"
            dDefinition.ConnectString = "Data Source=" & sqlServerName & ";Initial Catalog=" &skm5DbName
            System.Diagnostics.Trace.WriteLine(dDefinition.ConnectString.ToString())
            dDefinition.ImpersonateUserSpecified = True
            dDefinition.Prompt = Nothing
            dDefinition.WindowsCredentials = True
            dDefinition.UserName = uid
            dDefinition.Password = pwd
            dDefinition.CredentialRetrieval = CredentialRetrievalEnum.Store
            dSource.Name = skm5DataSourceName
            Try

                rs.CreateDataSource(skm5DataSourceName, dataSourceLocation, True, dDefinition, Nothing)

            Catch ex As System.Web.Services.Protocols.SoapException
                Console.WriteLine(ex.Detail.InnerXml.ToString())
            End Try

            ' Report and Datasource created, now fix up datasource reference to make sure report points at correct ds
            System.Diagnostics.Trace.WriteLine("DS Created")


        End Sub

        Private Sub Create skmAdminDataSource()
            Dim dSource As New DataSource()
            Dim dDefinition As New DataSourceDefinition()

            dSource.Item = dDefinition

            dDefinition.Extension = "SQL"
            dDefinition.ConnectString = "Data Source=" & sqlServerName & ";Initial Catalog=" & skmAdminDbName
            System.Diagnostics.Trace.WriteLine(dDefinition.ConnectString.ToString())
            dDefinition.ImpersonateUserSpecified = True
            dDefinition.Prompt = Nothing
            dDefinition.WindowsCredentials = True
            dDefinition.UserName = uid
            dDefinition.Password = pwd
            dDefinition.CredentialRetrieval = CredentialRetrievalEnum.Store
            dSource.Name = skmDataSourceName

            Try

                rs.CreateDataSource(skmAdminDataSourceName, dataSourceLocation, True, dDefinition, Nothing)

            Catch ex As System.Web.Services.Protocols.SoapException
                Console.WriteLine(ex.Detail.InnerXml.ToString())
            End Try

            ' Report and Datasource created, now fix up datasource reference to make sure report points at correct ds
            System.Diagnostics.Trace.WriteLine("DS Created")
        End Sub

        Private Sub CreateSamReportFiles(reportPath As String)
            Dim reportDefinition As Byte()
            Dim warnings As SamRdlClassLibrary.SamWebServiceReference.Warning()
            Dim stream As FileStream = File.OpenRead(finalPath + "\" + reportPath)
            reportDefinition = New [Byte](stream.Length - 1) {}
            stream.Read(reportDefinition, 0, CInt(stream.Length))
            stream.Close()

            warnings = DirectCast(rs.CreateReport(reportPath.Remove(reportPath.Length - 4, 4), "/skmRS", True, reportDefinition, Nothing), SamRdlClassLibrary.SamWebServiceReference.Warning())
        End Sub

        Private Sub SetReportFileReference(referenceSetting As String)
            Try

                Dim reference As New DataSourceReference()
                Dim ds As New DataSource()
                'reference.Reference = dataSourceLocation & "/" & skm5DataSourceName
                Dim strCurrentFileName As String = referenceSetting.Substring(0, referenceSetting.Length - 4)
                Dim dsarray As DataSource() = rs.GetItemDataSources(strCurrentFileName)
                Dim count As Integer = 0
                count = dsarray.Length
                For i = 0 To count - 1
                    If (dsarray(i).Name.ToUpper() = "SAM") Then
                        reference.Reference = dataSourceLocation & "/" & skm5DataSourceName
                    Else
                        reference.Reference = dataSourceLocation & "/" & SamAdminDataSourceName
                    End If

                    ds = dsarray(i)
                    ds.Item = DirectCast(reference, DataSourceReference)
                    Try
                        rs.SetItemDataSources(strCurrentFileName, dsarray)
                    Catch ex As Exception

                    End Try

                Next

             
            Catch ex As System.Web.Services.Protocols.SoapException
                Console.WriteLine(ex.Detail.InnerXml.ToString())
            End Try
        End Sub

    The bold line above throw error :The value of parameter 'DataSources' is not valid  when it found two datasources in a report file i.e when for loop runs two times. for single source it works fine.

    What i am missing????

    Thanks

    Skm

Tutte le risposte

  • mercoledì 20 giugno 2012 02:29
     
     
    Hi Shambhu,
    Welcome to the MSDN forum.
    This is a Report Controls issue. In order to give you a better support , I will move it from “Visual Basic Language” forum to “Visual Studio Report Controls” forum.
    Thank you for your understanding!
    Best regards,

    Shanks Zen
    MSDN Community Support | Feedback to us