This is a migrated thread and some comments may be shown as answers.

Problem with dynamic sql

6 Answers 406 Views
Report Designer (standalone)
This is a migrated thread and some comments may be shown as answers.
Dijar
Top achievements
Rank 1
Dijar asked on 22 May 2019, 05:04 PM

Hello,

I have a stored procedure which has dynamic sql in it with 'EXECUTE (@sql);', and im trying to create a table in report designer but no fields show up when i configure the data source. The query executes fine within the configuration and it has the result that i want but when i finish it there are no fields in the data explorer.

6 Answers, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 27 May 2019, 10:55 AM
Hi Dijar,

The issue as described is not known for us and we would like to investigate it.
Could you send us more details about the exact scenario, the code of the Stored Procedure and a runnable sample report (e.g with dummy database) so that we can test locally?

Regards,
Neli
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Dijar
Top achievements
Rank 1
answered on 28 May 2019, 12:39 PM
The problem appears to be when trying to use cursor variables in sql dynamic script. I have used AdventureWorks2017 database for the code in the attachment below.
0
Neli
Telerik team
answered on 31 May 2019, 12:27 PM
Hello Dijar,

To be able to use stored procedures which contain cursors, you have to turn off FMTONLY in a seemingly never executed statement. In this way the data schema can be read by the Data Explorer as each state of IF-ELSE statements is evaluated when the SQL query is run by the SqlDataSource Wizard. The check will be skipped when the same SQL query is used by calling application at run-time.

You may use the approach from How to configure Stored Procedure with Temporary Tables for use with SqlDataSource component KB article and modify the stored procedure as follows:

BEGIN
        SET NOCOUNT ON;
         IF 1=0 BEGIN
           SET FMTONLY OFF
     END
    DECLARE @SQL NVARCHAR(MAX)
    DECLARE @Next NVARCHAR(MAX)
    DECLARE db_cursor CURSOR FOR SELECT  DISTINCT Gender From HumanResources.Employee
        . . .
 
END
GO


Regards,
Neli
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items

Charanpreet
Top achievements
Rank 1
Veteran
commented on 29 Apr 2021, 06:38 PM

Thanks a lot

This works well

SET NOCOUNT ON;
IF 1=0 BEGIN
SET FMTONLY OFF
END
0
Dijar
Top achievements
Rank 1
answered on 20 Jun 2019, 03:48 PM
I encountered this problem again in a different stored procedure and i tried turning off FMTONLY in a seemingly never executed statement and also by using memory optimized tables but they didnt fix it. I even tried working around cursor by using loops but im facing the same problem.
0
Dijar
Top achievements
Rank 1
answered on 20 Jun 2019, 03:57 PM
It only seems to occur in stored procedures which have dynamic sql string that is executed.
0
Neli
Telerik team
answered on 25 Jun 2019, 11:59 AM
Hello Dijar,

The Reporting engine uses the specified ADO.NET provider in run-time to connect to the database, execute the query (select command) and return the data to the engine. Hence, if the provider manages to execute the query and return the data, our code should be able to display it successfully.

Please, specify in what way do you want to use the dynamic SQL string? What is the exact scenario?

You might find helpful How to use dynamic SQL string? article in Stack Overflow. 


Regards,
Neli
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Charanpreet
Top achievements
Rank 1
Veteran
commented on 29 Apr 2021, 06:37 PM

This works
SET NOCOUNT ON;
IF 1=0 BEGIN
SET FMTONLY OFF
END
Tags
Report Designer (standalone)
Asked by
Dijar
Top achievements
Rank 1
Answers by
Neli
Telerik team
Dijar
Top achievements
Rank 1
Share this question
or