How to make a SSRS work for multiple users - sql-server

I can't find anything on this so I don't think I am asking the question right but here is my situation. I have a stored procedure which the end user passes a list of filter criteria, since I don't know what the filter criteria will be I used dynamic SQL. Further, to allow for more than one user to run the stored procedure concurrently I used all dynamically named temp tables so there would be no collisions. That all works.
Now my problem is how to output the report. Right now I have a SSRS report pointing to a single database that the stored procedure dumps its output to. When the stored procedure finishes the report is displayed. This works for one user but if two users run the stored procedure at the same time I have no way of knowing which output data will show on the report. Complicating issues is the dynamic user filter criteria can greatly effect the time the stored procedure takes to complete. I can see the report loading data just as the other stored procedure session is truncating or loading data to the output table.
I can queue up requests and run them one at a time but ideally I want them to be able to run concurrently as several users have to run this report many times at the beginning of each month. Is there a way to ensure that the data displayed on the report to the end user matches the data output from the stored procedure session the user ran.
EDIT:
The following is not a requirement but to clarify how this works now, the end user goes to an web site, enters in some filter criteria into a bunch of text boxes, one for each filterable database field, using a third parties search wildcards format that they already know. I then take that input, clean it up and parse it into a SQL WHILE string which is then passed to the stored procedure that gets the data. When the stored procedure finishes control is passed back to the website that then displays the report as an imbedded object. So the website is calling the parsing method, the stored procedure and the report.

SQL Server will create a separate session for each report user. It will then invoke the stored procedure in its own session (SQL Server is a multi session product) and using the selected parameters will run the proc and produce unique results which will then be passed back to the report user who invoked it and the report will then be shown to the user. If ten users simultaneously invoke the report, with unique parameters, they will each see a different report in the body of the report.

I ended up reworking the whole thing as Benjamin suggested and it works fine but that really was not the answer I was looking for. I finally stumbled upon it while researching something else. You can set the report viewer's DataSources.Add() method to add your own dataset. This would have allowed me to run the stored procedure in the webpage so I can catch and handle the errors at the webpage level so I could give more useful feedback to the end users. You can see this other post setting the datasource for a local report net report viewer for more detail.
The example is for a local report but I was able to get it to work on a remote report but I am on a trusted internal only network. As I understand it, you can also do it with the newer report viewers too.

Related

Stored procedure works in SQL Server/SSRS query designer. Report body is empty

I have a stored procedure that runs successfully in SQL Server that is not loading anything into the body of the report. There are only 4 parameters to this procedure, 2 varchars and 2 ints.
I have verified the following:
The stored procedure works in SQL Server
The stored procedure works in SSRS when using Query Designer
The stored procedure shows as being executed and completed in SQL Server Profiler
Running what is shown in the SQL Server Profiler does return the expected results
There is no filtering on the table containing the results
There is no visibility restrictions on the table containing the results
The connection to the database is successful using "Test connection" as mentioned here
I have added a second different dataset into the report and it is showing in the body with no problems.
I have recompiled the procedure as mentioned here and it is still not showing in the report.
There are no multi valued parameters, so this answer is mostly irrelevant.
We are not using Visual Studio, so there is no .DATA files like mentioned here
However for the life of me, I can not get anything from this stored procedure to show up in the body of the report.
Due to legal reasons, the stored procedure cannot be posted in this question as it was part of a software our company is using. We have permission from them to use the procedure to make the SSRS Report for our needs.
Further diagnostics and logging are always useful.
You could have the procedure log additional data to a dedicated table for review later.
Useful data would be that which is related to the user's session based on ##spid and the system views sys.dm_exec_sessions, sys.dm_exec_requests, sys.dm_exec_input_buffer() such as statement start time, any blocking spids, wait_types. Also check the connection level properties are consistent and as expected eg quoted_identifier, ansi-settings etc.
You could also log information about the executing queries such as Rows Affected ##rowcount and the values of any parameters or intermediate values.

SSRS Report Dataset Not Showing Correct Data for Two Fields

Firstly some background on the environment..
RDL's are designed in Report Builder 3.0 (The pre-2016 one).
RDL's are hosted on what appears to be an SSRS 2014 Reporting Services server (Reason why I am saying appears to be is because the alias of the Report Manager and Web Service URL is "SSRS_2014" (And the DBA's told me so)).
Our database server is either running SQL Server 2014 or 2016. I am running SQL Server 2017 on my workstation.
The problem:
I have an SSRS report data set that retrieves information from a very standard stored procedure. Recently I had to change one line of code and add a column related to this change to the result set. Stored procedure works as expected when testing it in SSMS Query Analyser. Here’s an excerpt of the intended results:
But after refreshing the dataset (which adds the new column) the dataset now returns inconsistent values under two columns for all the records returned whilst the stored procedure that retrieves the data is returning values when I run it in SSMS. Even when I run it in Query Designer it still returns inconsistent values.
Here’s a screenshot:
This is not a shared data set and from what I can gather the report does not have any caching applied. When trying to see if there is, or when trying to setup caching the Report Manager returns the following error:
An error occurred within the report server database. This may be due to a connection failure, timeout or low disk condition within the database. (rsReportServerDatabaseError)
Get Online Help For more information about this error navigate to the report server on the local server machine, or enable remote Errors.
As below:
This behaviour is occurring even under the following circumstances:
I deleted and added the data set.
I deleted and added the data source.
I created a new data source.
I created a new RDL.
I created a copy of the stored procedure (Renamed slightly).
I added copies of these columns (Renamed slightly) to the stored procedure (They behave the same).
Fiddled with the “Use single transaction when processing the queries” option (Was off).
The clinchers:
(Bear in mind that the stored procedure returns the data correcting in SSMS).
- When I hard-code the values in the stored procedure, these values appear when executing the stored procedure via SSMS Query Analyser but not when running it via Query Designer (Same inconsistent values).
- I have another (summary) report that obtains data from this stored procedure (Embedded) via another procedure. That report returns the data correctly.
- I tried to create a second stored procedure that executes this stored procedure (Similarly to what the “summary” one does) and it still misbehaves.
- When I take the script that I use to test the stored procedure in SSMS Query Analyser it returns the values! But this is not ideal because the parameters are defined and when I remove those parameters it goes back to normal (mis)behaviour.
I was considering adding a type of snapshot table. Where the stored procedure would first build the data and then do a select from this table to return the data. The problem here is this report is run my multiple users and I do not have the time (3 days before Christmas and I am already on Christmas leave) do go and design a whole snapshot system.
I did a lot of research on the internet yesterday. And went through all suggestions given in the following sites/forums to no avail:
Why is my SSRS report showing old data?
SSRS: field shows correct in query but wrong in report preview
How to clear cache of 1 stored procedure in sql server
https://jazz.net/forum/questions/243993/report-builder-not-showing-updated-data
https://learn.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-freeproccache-transact-sql?view=sql-server-2017
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/e6f86f15-420c-4b64-bc70-01dea93a0995/report-results-and-query-results-returning-different-number-of-rows-why?forum=sqlreportingservices
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/9bc13904-a727-4786-9a11-693570f5f8d4/diable-the-cache-for-all-reports-in-ssrs-2008?forum=sqlreportingservices
And various other ones about caching and so on.
I even got the DBA’s to restart that SSRS server to see if that might refresh any forms of caching.
I also added “WITH RECOMPILE” hint to the stored procedure to no avail.
So I am at a loss… I am at this stage thinking of taking the Stored procedure’s code and running it as an embedded query but that is not best practice.
We are also in the process of handing this project over to another company so I don’t want to leave them this (I have my pride).

Crystal Reports: only field headers showing up. No data

I'm new to CR (this is my first experience in fact). I'm trying to create a report based on a stored procedure I created in SQL Server 2012.
The SP is relatively simple and it runs just fine within SQL Server: all the data is right there in the results.
However, when I created a new standard report in Crystal Reports (2013), I'm able to access my server and database, select the SP, and the fields I want to use. It goes smoothly until I select "Finish". When the report loads, there's only the field headers from the SP.
I'm lost. I've tried it many times and continue to have no data. When I right-click to check the connection, it confirms connection. When I right-click on a field in the field explorer (I believe it's called) to view the data, there's nothing there.
The strange thing is, I created a view in SQL Server with the same query and when I added that view to CR, it worked fine. All my data was right there.
I also tried using a few other SPs in the database and I had the same issue —headers with no data, so I'm pretty confident it's not the SP itself.
Note: after selecting my SP and field when starting a new CR, I'm presented a window to choose the data range (which I assume is based on a date time parameter I have built into the SP). I didn't choose a date range because the end user will be selecting the range they need, so I checked the null boxes. I doubt if this plays any part, but I figured I'd mention it.
There must be something simple I'm missing here. I just don't get it. Any ideas? Thanks for taking the time to help.
put your code and SP so that i can identify

Create PDF automatically after new entry in database

I am not sure if this is even the right site for this but I'll ask anyways.
Does anybody know a program that can create a PDF with data from a database with a complex SQL statement? When an employee finishes a request for a customer, I want that the program is triggered by the new entry in a database table and fills out a pre built PDF with data that it pulls from a database.
It needs to be a complex program that can process big SQL statements.
The only thing you can do to run custom code in SQL Server is to create a CRL Stored Procedure and a trigger to start PDF processing in your specific use case. You can write a class library that connects to the database you are triggered from using a specific keyword in the connection string. You can pass in the key you need to use to select the whole dataset you need to fill the PDF as a SP parameter.
https://msdn.microsoft.com/en-us/library/ms131094.aspx
In the class library you can reference third part libraries to interact with an editable PDF and fill the flieds you need with the data retrieved from the database. I suggest you to have a look about security concerns releted to CLR use in SQL Server. Basically your code runs within the SQLServer.exe process, sharing resources and access privileges.
https://msdn.microsoft.com/en-us/library/ms131071.aspx
SSRS can produce PDF. See if that table insert trigger can call a CLR that in turn will execute the report that can even be attached to an email.
The report can be as complex as you need, so long the report SP can populate the data based on the newly inserted row.
For stability, let's not have a trigger, but the insert process itself should be done in an SP, in which that insertion SP shall call the CLR.
Further, instead of using CLR, we can use SSRS Data-Driven Subscription. When making the Subscription, we can make it as a one time scheduled Job. The SP can invoke this 'expired' Job from SQL Server Agent by using sp_start_job.

Problem ReCreating Access report in Crystal Reports

I'm trying to recreate an access report as a crystal report and I'm having trouble.
Basically, the Access report runs a stored procedure (which returns nothing, but populates tables), then those tables are queried to display the data on the report.
So I'm trying to figure out how to run the procedure with parameters from a crystal report. I've got the second part fine, if I run the procedure manually, then display the report I get the appropriate data.
How can I execute the stored procedure before querying those tables from Crystal Reports???
Have you tried combining the stored procedure and the queries into one stored procedure? Execute the one that populates the tables, and then run the queries that return the data?
Use Visual Studio (Assumes you were using Access, so you may be a Microsoft shop.) to create a form that triggers the stored procedure and then opens the Crystal Report.
This way users don't have to have Crystal Reports installed. Just your app.
Can you get away with a combined Access & Crystal approach?
The Access db prompts the user for parameters and does whatever it needs to get & filter the data from the db.
Crystal generates it's report using the Access db as it's source.
This would be like taking the original Access file, deleting just the report, and recreating just the report in Crystal, using the original Access queries as your source.

Resources