ReportProcessingException: query execution failed for dataset - reporting-services

I created a report and when I try to preview it the following message is displayed :
Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Query execution failed for dataset XXXXX.
I run the query I'm using in the dataset and it works . I used the Query Designer in Dataset Properties and the SQL Server Management Studio. Tested the connections to DataSource and it is created successfully.
It isn't a permissions problem because I created other reports that run without problems.
Any ideas?

In my query I noticed some items had square brackets around them and some didn't.
I put square brackets around all items in the select statement and this error went away.
BEFORE:
SELECT [ID], Name, Value
FROM Table
AFTER:
SELECT [ID], [Name], [Value]
FROM Table

Related

Change database based on parameters in SSRS

Im trying to retrieve data from our SQL server with the Report Builder. Since we have different databases for different customers I want to switch the database, the table I query has the same name in every database.
The idea I have is to use a parameter, so this is what I came up with:
use #db
Select H.TK_RC, R.Result_Description, count(*) as aantal from dbo.TK_HISTORY as H
LEFT JOIN CWESystemConfig..Result_Code as R on H.Project_ID = R.Project_ID and H.TK_RC = R.Result_Code
Where R.Result_Group = 1 and H.Project_ID = #pid and H.TK_CD between #startdate and #enddate
group by H.TK_RC, R.Result_Description
The code itself is working, the problem I encounter is when I create a dataset in the report builder. I think it's because the report builder can't find a startingpoint(of course) it keeps throwing the "define query parameters" pop-up, whatever I do it gives me the error:
Could not update a list of fields for the query. Verify that you can connect to the datasource etc.
If I remove the use #db it does work, so this is the issue. I can see the issue, since this is a variable the report builder doesn't see a valid query.
I just can't get this to work, anyone with suggestions for a fix or a workaround?
You should be able to do this by using an expression as your datasource connection string. There is no need to use the USE statement in your dataset query.
For a simple connection to SQL Server you would use something like
="data source=mySQLServer;initial catalog=" & Parameters!db.Value
Where your #db parameter has the name of the database
NOTES:
You must use an embedded datasource - you cannot expressions in a shared datasource
You should design and test the report using a fixed connection, then once your are happy with it, change the connection to use an expression.
Here's an screen shot of what you should be looking at

SSIS Execute SQL Task error no rows returned

I am a bit new to SSIS and given a task to send mail to particular stores based on Purchase Orders -> PONumber.
The steps should be as follows:
1)Take a XML file from a particular folder
2)Get the PONumber from that file
3)Write a query to fetch all the store email addresses for PONumbers
4)Send a mail to particular restaurant
Below screenshot is a package I had created. The only thing I am getting an issue is the Execute SQL Task , not sure what is the exact cause?
Could you please help on how can I debug this ? This was working fine before, but suddenly it started showing errors.
IMAGE1
IMAGE5
Execute SQL task is expecting results from the query, but is not getting any. Maybe you could use SQL Server profiler to catch exact SQL that is executed on SQL Server. Then you can use that SQL in query window to troubleshoot what it returns or why it is not not giving any results.
Edit.
With your current additional information interesting place is "parameter mapping" page, which you did not include. You should link SSIS variable to query parameter in there as Matt explained. SSIS does NOT link your variables in SSIS and query automatically even if they have the same names.
#dvlpr is correct your problem is you are getting NO results when Execute SQL Task 1 needs a single result.
The code you pasted is a little unclear as to which code is where but I will assume the first part is the code you use in SSIS Execute Task and the latter is an example in SSMS. If that is the case the problem is you are assigning the variable with a value of 0 in the script itself which I assume there is no PONUMBER that is 0:
Declare #POID as Varchar(50)
Set #POID = 0
WHERE (BizTalk_POA_HEADER.PONUMBER = #POID)
If you want to pass in the PONUMBER from your first dataflow task you need to load that to a variable and then use the variable in your Execute SQL task and made sure you setup parameter mapping correctly when doing so. here is one SO question on parameters that will help How to pass variable as a parameter in Execute SQL Task SSIS? And here is use of an expression task in a Data Flow task to set the variables value SSIS set result set from data flow to variable (note use the non-accepted answer that it was added later and was for 2012+ while the original was for 2008)
Next unless you are guaranteed only 1 result you will also need to add TOP 1 to your select statement because if you get more than 1 result you will get a different error again.
EDIT Per all of the comments:
So the configuration looks like you are using an ADO.NET connection which allows you to use named paramaters. There are restrictions if you don use that (https://msdn.microsoft.com/en-us/library/cc280502.aspx). The parameter mapping looks correct, and the result set should be fine. As far as your Error I don't know because you haven't posted the exact error so I cannot know what is the problem. If you use ADO.Net with your current Execute SQL Task configuration in the images you do have a couple of problems. 1 you are trying to declare the variable that you want to pass as a parameter that doesn't work, you need to remove that DECLARE statement. I suspect all you really need to do is modify your SQL Input to be:
SELECT DISTINCT BizTalk_POA_HEADER.PONUMBER, FAN_Suppliers.SupplierName,
FAN_Company_Details.CompanyName, FAN_Company_Details.[PrimaryEmail],
BizTalk_POA_HEADER.[DeliveryDate]
FROM BizTalk_POA_HEADER INNER JOIN
FAN_PO_Details ON BizTalk_POA_HEADER.PONUMBER =
CONCAT('PO',FAN_PO_Details.PoNumber) INNER JOIN
FAN_PO ON FAN_PO_Details.PurchaseOrderID = FAN_PO.PurchaseOrderID
INNER JOIN FAN_SupplierDetails ON FAN_PO.SupplierDetailsID =
FAN_SupplierDetails.SuppliersDetailsID INNER JOIN
FAN_Suppliers ON FAN_SupplierDetails.SupplierID = FAN_Suppliers.SupplierID
INNER JOIN FAN_Company_Details ON FAN_PO.CompanyID =
FAN_Company_Details.CompanyDetailsID
WHERE (BizTalk_POA_HEADER.PONUMBER = #POID)
Just get rid of the declare #POID and SET = 0 for a couple of reasons 1 because it is redundant when you have setup parameter mapping, 2 SSIS doesn't like it and will throw an error, 3 because you are setting a value of 0 to it which means it would always be 0.....

Connecting to Microsoft Analysis Server using SSIS Import/Export-Assistant

Goal is to export Data from a Microsoft Analysis Server Cube into a flatfile in a lean way.
I use the SQL Server-Import/Export-Assistant.
Using the option "Copy data from one or more tables or views" the download runs smoothly. -> No problems
When I use an MDX expression ("Write a query to specify the data to transfer") query pre-executing it gives an error message
Error 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E21.
Edit: Please note that I try to run the SQL Server 2016 RC0 Import and Export Data Wizard -> Must use this one as it is the only valid licence.
Edit:
I recognized differences in the following MDX expressions.
Query 1
SELECT
[Measures].[measure1] ON COLUMNS,
NON EMPTY
[order].[orderid].[orderid].AllMembers
* [order_spec].[spec].[spec].AllMembers ON ROWS
FROM [cube];
SQL Server 2014 Management Studio: works
SQL Server Import and Export Data Wizard: Error 0x80040E21
Visual Studio 2015, Data Flow Task: Error 0x80040E21
Query 2
SELECT * FROM
[cube].[cube_tab].[$spec2]
SQL Server 2014 Management Studio: works
SQL Server Import and Export Data Wizard: works
Visual Studio 2015, Data Flow Task: works
Also note, that when I use the option "Copy data from one or more tables or views" I cannot choose any measures.
Also I am not able to set up any openquery procedure using the Wizard.
Looks like you have SQL-server
Create a linked server to the cube database
You can then write an mdx query inside a tsql query like described here: https://technet.microsoft.com/en-us/library/aa936673(v=sql.80).aspx
I used scripts in the form of the last snippet in the above reference:
select * from openquery
( LINKED_OLAP, 'select { measures.[unit sales] } on columns,
non empty nest( nest( [customer location].[country].members,
[gender].members ), [product category].[bread].children ) on rows
from sales ')
If the above looks like a possibility then I would strongly suggest going straight to the following - it is a wonderful stored procedure:
https://olapextensions.codeplex.com/
Edit
This isn't standard mdx:
SELECT
{[Measures].[measure1]}
DIMENSION PROPERTIES
[MEMBER_UNIQUE_NAME]
,[MEMBER_CAPTION] ON COLUMNS,
NON EMPTY
CROSSJOIN(
[order].[orderid].[orderid].AllMembers,
[order_spec].[spec].[spec].AllMembers
)
DIMENSION PROPERTIES
[MEMBER_UNIQUE_NAME]
,[MEMBER_CAPTION] ON ROWS
FROM [cube]
This is a lot simpler:
SELECT
[Measures].[measure1] ON COLUMNS,
NON EMPTY
[order].[orderid].[orderid].AllMembers,
* [order_spec].[spec].[spec].AllMembers
ON ROWS
FROM [cube];
Maybe this is also sufficient:
SELECT
[Measures].[measure1] ON COLUMNS,
NON EMPTY
[order].[orderid].[orderid].MEMBERS,
* [order_spec].[spec].[spec].MEMBERS
ON ROWS
FROM [cube];

Data Flow Task - Using a parameter in a SQL Command in OLE DB Source

I have the following SQL Command in an OLE DB Source, in a data flow task:
Select Top 5000 *
From ProcessHistory.ScribeDeadZone1
Where ScribeDeadZoneId > ?
At the moment this works fine. However, I'd like to replace the 5000 with a variable. I can't seem to get the syntax right because everything I try results in an error when I click the Parameters button to set the parameter. I've tried
Select Top ? * and Select Top (?) *. Is this possible to do?
You need to build the SQL statement in a variable and then use the SQL Command from Variable option when defining the data source.

SSIS Package Fails on Status Code 4

I've created an SSIS package that executes inline SQL queries from our database and is supposed to output the contents to a text file. I originally had the text file comma delimited, but changed to pipe delimted after researching the error further. I also did a substring of the FirstName field and ensure that the SSIS placeholder fields matched in length. The error message is as follows:
[Customers Flat File [196]] Error: Data conversion failed. The data conversion for
column "FirstName" returned status value 4 and status text "Text was truncated or one or more
characters had no match in the target code page.".
The SQL statement I'm using in my OLE DB Source is as follows:
SELECT
dbo.Customer.Email, SUBSTRING(dbo.Customer.FirstName, 1, 100) AS FirstName,
dbo.Customer.LastName, dbo.Customer.Gender,
dbo.Customer.DateOfBirth, dbo.Address.Zip, dbo.Customer.CustomerID, dbo.Customer.IsRegistered
FROM
dbo.Customer INNER JOIN
dbo.Address ON dbo.Customer.CustomerID = dbo.Address.CustomerID
What other fixes should I put in place to ensure the package runs without error?
Have you tried to run this query in SSMS? If so, did you get a successful result?
If you havent tried it yet, paste this query in a new SSMS window and wait for it to complete.
If the Query completes, then we dont have a problem with the query. Something could be off inside the package.
But if the query does not finish up and fails, you know where to look.
EDIT
On second thoughts, is your Customer source a flat file or something? It looks like there is a value in the Customer table/file which does not match with the output metadata of the source. Check your source again.