简体   繁体   English

具有直接查询模式的Azure SQL数据库中存储过程的用法

[英]Stored Procedure usage in Azure SQL Database with Direct Query Mode

I have created stored procedures in Azure SQL Database and trying to use them power BI report with Direct Query mode. 我已经在Azure SQL数据库中创建了存储过程,并尝试在Direct Query模式下将它们用于Power BI报表。 But getting the error like 但是出现错误

"Microsoft SQL: Incorrect syntax near the keyword 'EXEC'. Incorrect syntax near ')'. "Microsoft SQL: Incorrect syntax near the keyword 'EXEC'.附近的语法不正确"Microsoft SQL: Incorrect syntax near the keyword 'EXEC'. ')'附近的语法不正确。

Another question is 另一个问题是

how to set the connection string as global so that I can use the same connection string in multiple reports? 如何将连接字符串设置为全局,以便可以在多个报表中使用相同的连接字符串?

Please help me with the solution 请帮我解决

I assume you are using Power BI Desktop. 我假设您正在使用Power BI Desktop。 When it constructs a DirectQuery SQL query it does this: 在构造DirectQuery SQL查询时,它会执行以下操作:

Select column1
From (
 YourQuery
) as t1

So it fails because you can't put EXEC in the from clause of a SELECT query. 因此它失败了,因为您不能将EXEC放在SELECT查询的from子句中。

Your options: 您的选择:

  1. Stop using DirectQuery. 停止使用DirectQuery。 Using a stored proc in cached mode will work because it just runs your query without any changes during refresh. 在缓存模式下使用存储的proc是可行的,因为它只运行查询,而刷新期间未做任何更改。 Why would this not work for you? 为什么这对您不起作用?

  2. Take the query out of the stored proc and put it inline into PBI Desktop. 从存储的proc中取出查询,并将其内联到PBI Desktop中。 Then it should work with DirectQuery as long as it is a single statement simple select. 然后,它应该与DirectQuery一起使用,只要它是单个语句简单选择即可。

Regarding reusing the connection (and I assume you also mean reusing the model with calcs, relationships, etc) in another report. 关于重用连接(我还假设您的意思还意味着重用带有计算,关系等的模型)。 Turn on this new preview feature under PBI Desktop options and you can connect to a published dataset (the model/data/connection) in Power BI Service. 打开PBI Desktop选项下的此新预览功能 ,您可以在Power BI Service中连接到已发布的数据集(模型/数据/连接)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM