In SSRS how can we switch shared data sources based on condition.
I do have two shared data sources and one should be used when user access with admin access and other data sources should come into picture when user with other roles are using.
Can you guys help me with it?
You can create a new datasource setting a conditional connection string in the DataSource properties based on User!UserID running the report.
Use something like this:
=IIF(User!UserID = "YOURDOMAIN\Admin1",
"Data Source=MSSQLDB;Initial Catalog=DataBaseForAdmin",
"Data Source=MSSQLDB;Initial Catalog=DataBaseForNonAdmin"
)
Let me know if this helps.
Related
I am trying to create a dynamic data source in SSRS. I have a generic report that needs to be run across multiple database servers, requiring a way to connect to each based on a parameter.
I have setup my parameters in a way where I can generate the following connection string:
Data Source=172.16.1.111;Initial Catalog=TESTDB
If I plug that connection string into the "Connection String" text area field in the Data Source Properties window and click "Test Connection," I get the "Connection created successfully" message.
However, if I attempt to create an expression with the same data source (forget about the dynamic data source for a minute), like as shown below, I get a "The ConnectionString property has not been initialized" error message when trying to test the connection.
="Data Source=172.16.1.111;Initial Catalog=TESTDB"
Based on other examples I have seen looking this up online, this type of connection string definition is supposed to work.
My end goal is to create something like:
="Data Source=" + Parameter!Server.Value + ";Initial Catalog=" + Parameter!Database.Value
which would allow me to connect to any database based on the user selection.
Does anyone have any suggestions for what I might be doing wrong? I am using SQL Server 2014 Report Builder.
This ended up being an issue with the report builder. Once I deployed the report I was able to get this work. For some reason, even if you hard code the connection string as I mentioned above, expressions will not evaluate at runtime when running from within the report builder.
Hope this helps someone else in the future!
How to remove this prompt when viewing SSRS report in ASP.net
Can we pass these as two parameters?
The answer would depend on what kind of data provider you have.
Assuming this is an MS SQL data provider:
Go to the SSRS Report Manager, find your data source and open its properties.
Then, depending on the authentification method set up in your SQL server and the database, set the appropriate parameters:
"(o) Credentials stored securely in the report server" - if your server/database require the authorization and you want to provide the user name and password
"[x] Use as Windows credentials when connecting to the data source" - check this checkbox if your server/database configured for windows authentification, otherwise leave it unchecked.
"( ) Windows integrated security" - select this option if you'd like to use the current windows credentials of the report user
"( ) Credentials are not required" - in case if your data provider and data source don't require the authorization (which is unlikely though)
Hope it helps.
Best regards,
Alexey
www.kudinov.ru
You could also programmatically set the credentials of the data sources using the ReportViewer.ServerReport.SetDatasourceCredentials method. e.g.
// Set credentials
DataSourceCredentials cred = new DataSourceCredentials();
ReportDataSourceInfoCollection dataSource = this.ReportViewer.ServerReport.GetDataSources();
cred.Name = dataSource.First().Name;
cred.UserId = "userid";
cred.Password = "password";
this.ReportViewer.ServerReport.SetDataSourceCredentials(new DataSourceCredentials[] { cred });
this.ReportViewer.ServerReport.Refresh();
// Hide credential prompt
ReportViewer.ShowCredentialPrompts = false;
First time using SQL Server 2008 this morning.
I am trying to find a user defined function that I created. I cannot locate it in the "Programmability>Functions" branch of the object explorer. Here is what that branch looks like:
There do not seem to be any "user defined functions" and I don't know if any of the particular branches should house that. I have been granted database owner rights to the database, so I don't believe it is a permissions issue...
I was able to retrieve the full text of the function using the 'EXEC sp_HelpText 'someUserDefinedFunction'' that was listed in this thread about finding user defined functions. That thread did not provide enough information for me to locate my function in object explorer or edit my function again using SMSS. Please see the full screenshot of my SQL Server 2008 Management Studio instance with the return from the sp_HelpText query for additional context.
The function works just fine when it is called. I retrieved this function from this thread about splitting delimited text.
I am hoping to find a location in the interface that displays all the user defined functions!
There is no "user defined functions" menu in SSMS. All functions except system are user defined. Based on return type you will find your function in "Table-valued", "Scalar-valued", or "Aggregate" (the latest is not really different from "Scalar-valued" in terms of return type though, but it can be used for aggregation). In your case check "Table-valued"
I am trying to create a data driven subscription for a report that uses #UserID to filter the results (for security purposes). The solution I've seen referenced as the answer to several similar questions is a broken link.
We'd like to have a version that a user can access online as well as the subscription report that is emailed. Is there any way to do this without having two versions of the report (one with userID and one without)?
We have developed a solution that allows the same report to be used for live access as well as data-driven subscriptions (DDS). It is based on the concept found at the link provided by djphatic
To start, we return the #User value using custom code added to the report, instead of the User!UserID function which will make the DDS choke. The code is similar to the Prologika solution, but I found it at another online source--my apologies for not remembering where I found it. The code is:
Public Function GetHashedUser()
Try
Return Report.User!UserID
Catch
Return " "
End Try
End Function
For the user parameter default value we use:
=Code.GetHashedUser()
This returns the User!UserID if the report is being run live.
The data-driven subscription needs to have the user and other parameters passed using the query for the subscription. Since any parameters passed this way will be visible in the URL, we use a hashed version of the userID (called the userkey). The userkey corresponds to a value in our security table and can identify the user and their associated permissions. We don't encrypt the other filters, since they are based on the user and are used for drill-downs.
Please see the link below. I've not tested this myself but I've seen this solution mentioned before.
http://prologika.com/CS/blogs/blog/archive/2011/03/28/data-driven-subscriptions-and-row-level-security.aspx
I have a need to determine what security group(s) a user is a member of from within a SQL Server Reporting Services report. Access to the report will be driven by membership to one of two groups: 'report_name_summary' and 'report_name_detail'. Once the user is executing the report, we want to be able to use their membership (or lack of membership) in the 'report_name_detail' group to determine whether or not a "drill down" should be allowed.
I don't know of any way out of the box to access the current user's AD security group membership, but am open to any suggestions for being able to access this info from within the report.
You can add custom code to a report. This link has some examples.
Theoretically, you should be able to write some code like this, and then use the return value to show/hide what you want. You may have permissions problems with this method, though.
Public Function ShouldReportBeHidden() As Boolean
Dim Principal As New System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent())
If (Principal.IsInRole("MyADGroup")) Then
Return False
Else
Return True
End If
End Function
Alternatively, you could add your detail report as a subreport of your summary report. Then you could use the security functionality built in to SSRS to restrict access to your sub report.
In Reporting Services just use :
Public Function IsMemberOfGroup() As Boolean
If System.Threading.Thread.CurrentPrincipal.IsInRole("MyADGroup") Then
Return True
Else
Return False
End If
End Function
as indicated in this posting
Note: This works once the report is deployed to server but not in the IDE.