Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
criss317
Frequent Visitor

Can I execute a SP in DirectQuery Mode with or without parameters?

Hello everyone,

 

Many thnaks in advance!


I was trying to build a simple live report using DirectQuery but I was keep getting errorrs when the Stored Procedure was being executed and I was getting the following error message even though my syntax seemd to be ok


Perhaps, my syntax is not correct or what am I missing ?

 

criss317_0-1633604244514.png

 

1 ACCEPTED SOLUTION

Hi @criss317 ,

Please review the content in the following blogs and check whether they can help you achieve the requirement.

The first method:

Power BI DirectQuery with Parameterized Stored Procedure

1. Please set the source as below in Advanced Editor:

 

= Sql.Database("xxxxx", "AdventureWorksDW2014", [Query="SELECT * FROM #(lf)OPENROWSET('SQLNCLI','trusted_connection=yes', 
     'exec AdventureWorksDW2014..getProcategory')", CreateNavigationProperties=false])

 

yingyinr_0-1635313582509.png

2. By default, SQL Server does not allow ad hoc distributed queries using OPENROWSET and OPENDATASOURCE. So you will get the below error message. When this option is set to 1, SQL Server allows ad hoc access. Then you can connect to sql server successfully...

yingyinr_1-1635313858415.png

 

sp_configure 'show advanced options', 1;  
RECONFIGURE;
GO 
sp_configure 'Ad Hoc Distributed Queries', 1;  
RECONFIGURE;  
GO  

 

yingyinr_2-1635313966973.png

ad hoc distributed queries Server Configuration Option

The second method:

SQL Server and Power BI: How to load Stored Procedure data into SQL Server with DirectQuery

yingyinr_0-1633946640453.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
fmunar1985
Frequent Visitor

you have to put Import instead of DirectQuery 😉 

Thanks Munar, it works perfectly with the Import connectivity mode, but I need my data to be live not cached... That's why I was looking for a solution here. Any other thoughts on this one?

Hi @criss317 ,

Please review the content in the following blogs and check whether they can help you achieve the requirement.

The first method:

Power BI DirectQuery with Parameterized Stored Procedure

1. Please set the source as below in Advanced Editor:

 

= Sql.Database("xxxxx", "AdventureWorksDW2014", [Query="SELECT * FROM #(lf)OPENROWSET('SQLNCLI','trusted_connection=yes', 
     'exec AdventureWorksDW2014..getProcategory')", CreateNavigationProperties=false])

 

yingyinr_0-1635313582509.png

2. By default, SQL Server does not allow ad hoc distributed queries using OPENROWSET and OPENDATASOURCE. So you will get the below error message. When this option is set to 1, SQL Server allows ad hoc access. Then you can connect to sql server successfully...

yingyinr_1-1635313858415.png

 

sp_configure 'show advanced options', 1;  
RECONFIGURE;
GO 
sp_configure 'Ad Hoc Distributed Queries', 1;  
RECONFIGURE;  
GO  

 

yingyinr_2-1635313966973.png

ad hoc distributed queries Server Configuration Option

The second method:

SQL Server and Power BI: How to load Stored Procedure data into SQL Server with DirectQuery

yingyinr_0-1633946640453.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@Rena I have store procedure which have 3 parameters, can you please help me how to write the same in advance editor.

 

criss317
Frequent Visitor

Perhaps I should rephrase it or to give more details

1 - I have this simple stored procedure 

 

criss317_1-1633612631118.png

 

2 - I am trying to add this SP to my PBI desktop and to import it using the DirectQuery mode

 

criss317_2-1633612778384.png

3 - Data loads perfectly but in the moment I am applying those changes I am getting errors

 

criss317_3-1633613396425.png

 

amitchandak
Super User
Super User

@criss317 , in SQL server we do not give = when execute a proc

 

example

EXEC sp_procoption

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi Amit, thank you for your reply.
I did used this syntax now EXEC dbo.Settings_Sage_Companies and I am still getting the syntax error

Any thoughts on this one?

criss317_0-1633612426350.png

 

Hi @criss317 did you find a solution for this? 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.