364,088 Members | 5493 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Programmatically deploy SQL server 2005 reports and Datasource

balaki
P: 5
Hi,

I am working on a Installer Project, which requires to deploy SQL Server 2005 Reports (.rdl files) and Datasource (.rds file). The datasource is common for all reports. The report files are available in multiple folders (under D:\TestReport) and the .rds file is in a folder called 'Data Sources'. I wrote a VB.Net console application to do the task. I am able to deploy the report files under the specified folders. But I don't know how to deploy the rds file and assign that datasource to the report files.

I have created s datasource based on the input. The datasource is created, but when I browse the reports, the error "The report server cannot process the report. The data source connection information has been deleted. (rsInvalidDataSourceReference)" appears. Herewith I have attached the code I used. Somebody please help me in this regard.

Thanks,

Bala

Expand|Select|Wrap|Line Numbers
  1. Module Module1
  2.     Sub Main(ByVal Arg() As String)
  3.         Try
  4.             'If Arg.Length < 5 Then Exit Sub
  5.             Dim DBServer As String = "Server" 'Arg(0)
  6.             Dim DBName As String = "DBName" 'Arg(1)
  7.             Dim ReportServerURL As String = "http://localhost/ReportServer1/ReportService2005.asmx" 'Arg(2)
  8.             Dim ReportsParentFolder As String = "C:/TestReport" 'Arg(3)
  9.             Dim ReportParentFolderName As String = "DB Reports"  'Arg(4)
  10.  
  11.             Dim RServices As New ReportingService2005.ReportingService2005()
  12.             RServices.Credentials = System.Net.CredentialCache.DefaultCredentials
  13.             RServices.Url = ReportServerURL
  14.             RServices.CreateFolder(ReportParentFolderName, "/", Nothing)
  15.  
  16.             Dim ReportPath As String = ""
  17.             Dim ReportDef() As Byte
  18.             Dim DirInfo As New DirectoryInfo(ReportsParentFolder)
  19.             Dim CurrentFolderName As String = ReportsParentFolder
  20.             Dim CurReportFolderName As String = "/" & ReportParentFolderName
  21.  
  22.             ' Create datasource for the report.
  23.             Dim dDefinition As New ReportingService2005.DataSourceDefinition()
  24.             dDefinition.Extension = "SQL"
  25.             dDefinition.ConnectString = "Data Source=" + DBServer + ";Initial Catalog=" + DBName
  26.             dDefinition.ImpersonateUser = False
  27.             dDefinition.ImpersonateUserSpecified = True
  28.             dDefinition.Prompt = Nothing
  29.             dDefinition.WindowsCredentials = True
  30.             dDefinition.CredentialRetrieval = ReportingService2005.CredentialRetrievalEnum.Store
  31.             dDefinition.Enabled = True
  32.             dDefinition.EnabledSpecified = True
  33.             dDefinition.UserName = ""
  34.             dDefinition.Password = ""
  35.             dDefinition.WindowsCredentials = True
  36.  
  37.             For Each RdlFile As FileSystemInfo In DirInfo.GetFileSystemInfos
  38.                 If RdlFile.GetType.Name = "DirectoryInfo" Then ' it is a folder
  39.                     RServices.CreateFolder(RdlFile.Name, "/" & ReportParentFolderName, Nothing)
  40.                     CurrentFolderName = ReportsParentFolder & "/" & RdlFile.Name
  41.                     CurReportFolderName = CurReportFolderName & "/" & RdlFile.Name
  42.  
  43.                     Dim DirInfo1 As New DirectoryInfo(RdlFile.FullName)
  44.                     For Each RdlFile1 As FileSystemInfo In DirInfo1.GetFileSystemInfos
  45.                         If RdlFile1.GetType.Name <> "DirectoryInfo" Then
  46.                             ReportPath = RdlFile1.Name
  47.                             Dim File As New FileStream(CurrentFolderName & "/" & ReportPath, FileMode.Open)
  48.                             ReportDef = New Byte(File.Length) {}
  49.                             File.Read(ReportDef, 0, CInt(File.Length))
  50.                             File.Close()
  51.  
  52.                             If LCase(Mid(RdlFile1.Name, RdlFile1.Name.Length() - 2)) = "rdl" Then
  53.                                 RServices.CreateReport(ReportPath.Remove(ReportPath.Length - 4, 4), CurReportFolderName, True, ReportDef, Nothing)
  54.                             End If
  55.                             If LCase(Mid(RdlFile1.Name, RdlFile1.Name.Length() - 2)) = "rds" Then
  56.                                 RServices.CreateDataSource("ReportData", "/" & ReportParentFolderName & "/Data Sources", False, dDefinition, Nothing)
  57.                             End If
  58.  
  59.                         End If
  60.                     Next
  61.                 Else ' it is a rdl file
  62.                     ReportPath = RdlFile.Name
  63.                     Dim File As New FileStream(CurrentFolderName, FileMode.Open)
  64.                     ReportDef = New Byte(File.Length) {}
  65.                     File.Read(ReportDef, 0, CInt(File.Length))
  66.                     File.Close()
  67.                     RServices.CreateReport(ReportPath.Remove(ReportPath.Length - 4, 4), CurrentFolderName, True, ReportDef, Nothing)
  68.                 End If
  69.                 CurReportFolderName = "/" & ReportParentFolderName
  70.             Next
  71.  
  72.         Catch ex As Exception
  73.             Console.WriteLine(ex.Message)
  74.         End Try
  75.     End Sub
  76. End Module
Jan 18 '08 #1
Share this Question
Share on Google+
3 Replies


kenobewan
Expert 2.5K+
P: 4,721
It sounds like the RDL is not set correctly to point to where the datasource is being deployed. You can either change the RDL or call SetItemDatasources (RS 2005) or SetReportDatasources (RS 2000) to set the data source to point to the shared data source. HTH.
Jan 18 '08 #2

balaki
P: 5
Thanks for your response.
I tried using SetItemDatasources, but could not succeed. It will be very helpful, if you can provide me a code sample. Thanks in advance.
Jan 18 '08 #3

kenobewan
Expert 2.5K+
P: 4,721
Then show us what you tried. Thanks.
Jan 19 '08 #4

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework