0

I have this code to programmatically export a report to PDF.

Public Sub Main()

TRY

 DIM historyID as string = Nothing
 DIM deviceInfo as string = Nothing
 DIM extension as string = Nothing
 DIM encoding as string
 DIM mimeType as string = "application/Excel"
 DIM warnings() AS Warning = Nothing
 DIM streamIDs() as string = Nothing
 DIM results() as Byte


 rs.Credentials = System.Net.CredentialCache.DefaultCredentials
 Dim dataSources() As DataSource = rs.GetItemDataSources("foldername/reportname")

 rs.LoadReport(REPORTSERVER_FOLDER, historyID)

 results = rs.Render(FORMAT, deviceInfo, extension, mimeType, encoding, warnings, streamIDs)

 DIM stream As FileStream = File.OpenWrite(FILENAME)
 stream.Write(results, 0, results.Length)
 stream.Close()

Catch e As IOException
  Console.WriteLine(e.Message)
End Try

End Sub

When I run it I get an error saying:

error BC30002: Type 'DataSource' is not defined.

 Dim dataSources() As DataSource = rs.GetItemDataSources("foldername/reportname")
                      ~~~~~~~~~~

Am I forgetting to import something? If I remove that line it works fine (besides that it needs a data source to be added). Adding the data source beforehand is not an option.

A. Savva
  • 632
  • 10
  • 30
  • Firstly, you haven't told us what type `rs` is. We shouldn't have to guess or research stuff like that for ourselves. As for the issue, you haven't qualified the type name with a namespace and the error message suggests that you haven't imported that namespace either. You need to do one or the other for every type you use. – jmcilhinney Aug 21 '18 at 09:21
  • This is the right way: `Dim dataSources() As DataSources = rs.GetItemDataSources("foldername/reportname")` (note additional 's' on `DataSources`). – Tetsuya Yamamoto Aug 21 '18 at 09:25
  • @TetsuyaYamamoto that's not it, it's that I'm not importing it in some way, so the script doesn't know what it is. – A. Savva Aug 21 '18 at 10:55
  • @jmcilhinney `rs.exe` is the SSRS tool to execute commands that are related to reports. I don't know what type it is in the script, don't see how that is relevant either. I run the script with this command `"C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\rs.exe" -i C:\tools\EXPORTREPORT.rss -s "localhost/ReportServer_SQL2012" -v FILENAME="c:\tools\stores_near_me.pdf" -v REPORTSERVER_FOLDER="/AdventureWorks Sample Reports/Customers_Near_Stores" -t -v FORMAT="PDF" -e Exec2005` – A. Savva Aug 21 '18 at 11:15
  • How can you not know the type of a variable you're using in your code? Can you not just wave your mouse over it and have the IDE tell you? Can you not just look at the declaration? As for how it's relevant, you don't think it would be useful for us to check out that `GetItemDataSources` method to see exactly what type it returns? – jmcilhinney Aug 21 '18 at 22:45
  • This is a single file script and it's executed by running `rs.exe` as I wrote above. There is no declaration for `rs` and I am using Notepad++, which doesn't say. In either case, the type of it is [`ReportExecutionService`](https://learn.microsoft.com/en-us/dotnet/api/reportexecution2005.reportexecutionservice?view=sqlserver-2016), although it changes if you don't use the `Exec2005` endpoint, that's why I got confused. By running the command with the `Exec2005` endpoint you have a different set of methods and types that you can use, and `DataSource` is not included in it. – A. Savva Aug 22 '18 at 10:37
  • Are you trying to deploy reports on machinename/reports ? then i have got the whole code for it. i am not able to get to know that how have you created datasource ? – Krunal Shah Sep 24 '18 at 08:27
  • @KrunalShah check the answer below :) – A. Savva Sep 24 '18 at 14:54

1 Answers1

0

So I figured the answer. I am using the Exec2005 (execution endpoint), which does not include the definition for DataSource. I should instead use the default endpoint (Mgmt2005), but this causes other problems in the code.

In any case, the answer to this question is to not use -e Exec2005.

A. Savva
  • 632
  • 10
  • 30