Showing posts with label shared. Show all posts
Showing posts with label shared. Show all posts

Saturday, February 25, 2012

Access shared data source inside custom assembly

I have a database connection string hard-coded in a SQL Server 2005 Reporting Services custom assembly. Since the connection string is environment-specific (dev/prod), I would like to read the connections string from a settings file, like is typically done for web.config. Using the shared data source is also a good option.

How do I accomplish this?

I looked into trying to use DataSourceReference(), but that does not seem to be allowed inside of a custom assembly. Thank you.

Only private data sources can be expression-based. You can think of the Report Server as a web application since it runs under IIS. Therefore, you can put your config settings in the C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\web.config just like you would do with a regular ASP.NET app. Assuming you've deployed your report to the report catalog, you can read these settings at runtime . Additional considerations:

1. This technique is not supported.

2. Since there is no HttpContext in in the VS.NET Report Designer, you need to check for this condition and default your settings so you report works in design mode. I have a report in this download that demostrates how you can do this.

Access shared data source inside custom assembly

I have a database connection string hard-coded in a SQL Server 2005 Reporting Services custom assembly. Since the connection string is environment-specific (dev/prod), I would like to read the connections string from a settings file, like is typically done for web.config. Using the shared data source is also a good option.

How do I accomplish this?

I looked into trying to use DataSourceReference(), but that does not seem to be allowed inside of a custom assembly. Thank you.

Check Jason's blog here

http://weblogs.asp.net/jgaylord/archive/2005/05/12/406639.aspx

HTH
Regards

|||

Thank you. I read that blog, but it just seems to mention connection strings in general. The issue I am facing is that the Reporting Services assembly does not seem to allow me to access web.config, even though there is a web.config associated with RS. When I try to write "Imports System.Web.Configuration," VS2005 says it is not available and that the WebConfigurationManager is not available.

|||

Ok, simply add the System.Configurations.Dll as a reference in your project.

Let me know if you need further help.

Regards

Monday, February 13, 2012

Access Global Variables in Body

Is this possible? I am trying to access the global variables via custom code.
However I get this msg when I use the following code.
Public Shared Function Hello() As String
Return Globals.UserID
End Function
ERROR :- There is an error on line 1 of custom code: [BC30469] Reference to
a non-shared member requires an object reference.
I need to get the global variables Execution time, Page Number within the
body to format the report appropriatly.
Thanks in advance to helpers !In order to access the Global (or parameter for that matter) you have to
fully qualify it in the code window.
There are two fixes to your problem.
1. drag a text box to the report area
2. past something like this into it:
=Globals!PageNumber & " of " & Globals!TotalPages
3. run the report.
--
OR (doing it by ref from the code)
--
if you need to ref them from the code, the you have to declare them first in
your code like so:
Function pn()
Dim pn as String
pn = Report.Globals!PageNumber
Return pn
End Function
Function tp()
Dim tp as String
tp = Report.Globals!TotalPages
Return tp
End Function
----
Once you have that in the code window, you can type:
=Code.pn()
or
=Code.tp()
--
to get the pagenumber or total page global respectfully
"d pak" wrote:
> Is this possible? I am trying to access the global variables via custom code.
> However I get this msg when I use the following code.
> Public Shared Function Hello() As String
> Return Globals.UserID
> End Function
> ERROR :- There is an error on line 1 of custom code: [BC30469] Reference to
> a non-shared member requires an object reference.
> I need to get the global variables Execution time, Page Number within the
> body to format the report appropriatly.
> Thanks in advance to helpers !