使用 openquery 运行 MDX 查询时出现错误代码 7321

Posted

技术标签:

【中文标题】使用 openquery 运行 MDX 查询时出现错误代码 7321【英文标题】:Error code 7321 when running MDX query using openquery 【发布时间】:2015-12-17 05:48:57 【问题描述】:

您好,我编写了以下 MDX 查询,该查询从链接服务器上的多维数据集获取数据,

USE [BMS_Extracts]
GO
/****** Object:  StoredProcedure [dbo].[usp_CQ_SnP_Quotes]    Script Date: 12/17/2015 11:09:23 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER proc [dbo].[usp_CQ_SnP_Quotes] --'2016-Q4'
(
       @FisQuar varchar(20)
)
As

Declare @Mdx nvarchar(max)
Declare @FisMonthparam varchar(20)
Declare @FisMonthloop int

select (FISC_MTH_ID) as Monthloop,concat(left(min(FISC_MTH_ID),4) ,'-M',right(min(FISC_MTH_ID),2))as Monthparam into tbl_CQ_snp_quotes from calendar where cast(FISC_QTR_ID as varchar(10)) = concat(left(@FisQuar,4),right(@FisQuar,1)) group by FISC_MTH_ID

set @FisMonthloop = (select min(Monthloop) from tbl_CQ_snp_quotes)

print @FisMonthloop

while @FisMonthloop <= (select max(Monthloop) from tbl_CQ_snp_quotes)

begin

set @FisMonthparam = (select Monthparam from tbl_CQ_snp_quotes where Monthloop = @FisMonthloop )

print @FisMonthparam

set @mdx= ' insert into CQ_SnP_Quotes
select 
cast(cast([[Dimension - Account]].[Account ID]].[Account ID]].[MEMBER_CAPTION]]] as varchar(100)) as bigint) as [Account ID],
cast([[Dimension - Account]].[Account Name]].[Account Name]].[MEMBER_CAPTION]]] as varchar(200)) as [Account Name],
cast([[Dimension - Channel]].[Segment]].[Segment]].[MEMBER_CAPTION]]] as varchar(30)) as [Segment],
cast(cast([[Dimension - Account Team]].[SR Badge]].[SR Badge]].[MEMBER_CAPTION]]] as varchar(100)) as bigint) as [SR Badge],
cast(cast([[Dimension - Account Team]].[SR Mgr Badge]].[SR Mgr Badge]].[MEMBER_CAPTION]]] as varchar(100)) as bigint) as [SR Mgr Badge],
cast([[Dimension - Account Team]].[SR Mgr Name]].[SR Mgr Name]].[MEMBER_CAPTION]]] as varchar(30)) as [SR Mgr Name],
cast([[Dimension - Account Team]].[SR Name]].[SR Name]].[MEMBER_CAPTION]]] as varchar(30)) as [SR Name],
cast(cast([[Dimension - Fiscal Calendar]].[Date]].[Date]].[MEMBER_CAPTION]]] as varchar(100)) as datetime) as [Date],
cast([[Dimension - Fiscal Calendar]].[Fiscal Month]].[Fiscal Month]].[MEMBER_CAPTION]]] as varchar(30)) as [Fiscal Month],
cast([[Dimension - Fiscal Calendar]].[Fiscal Quarter]].[Fiscal Quarter]].[MEMBER_CAPTION]]] as varchar(30)) as [Fiscal Quarter],
cast([[Dimension - Fiscal Calendar]].[Fiscal Week]].[Fiscal Week]].[MEMBER_CAPTION]]] as varchar(30)) as [Fiscal Week],
cast([[Dimension - Product]].[Product LOB]].[Product LOB]].[MEMBER_CAPTION]]] as varchar(50)) as [Product LOB],
cast([[Dimension - Product]].[Product Brand]].[Product Brand]].[MEMBER_CAPTION]]] as varchar(50)) as [Product Brand],
cast(cast([[Base - Quote Offering]].[Quote Num]].[Quote Num]].[MEMBER_CAPTION]]] as varchar(100)) as bigint) as [Quote Num],
cast([[Base - Quote Offering]].[Converted Flag]].[Converted Flag]].[MEMBER_CAPTION]]] as varchar(30)) as [Converted Flag],
cast([[Custom - Product SnP]].[SnP LOB Level 1]].[SnP LOB Level 1]].[MEMBER_CAPTION]]] as varchar(100)) as [SnP LOB Level 1],
cast([[Custom - Product SnP]].[SnP LOB Level 2]].[SnP LOB Level 2]].[MEMBER_CAPTION]]] as varchar(100)) as [SnP LOB Level 2],
cast([[Custom - Product SnP]].[SnP LOB Level 3]].[SnP LOB Level 3]].[MEMBER_CAPTION]]] as varchar(100)) as [SnP LOB Level 3],
cast([[Custom - Product SnP]].[SnP LOB Level 4]].[SnP LOB Level 4]].[MEMBER_CAPTION]]] as varchar(100)) as [SnP LOB Level 4],
cast([[Custom - Product SnP]].[SnP LOB Level 5]].[SnP LOB Level 5]].[MEMBER_CAPTION]]] as varchar(100)) as [SnP LOB Level 5],
cast([[Custom - Product SnP]].[SnP LOB Level 6]].[SnP LOB Level 6]].[MEMBER_CAPTION]]] as varchar(100)) as [SnP LOB Level 6],
cast(cast([[Measures]].[Margin Quoted SnP]]] as varchar(100)) as float) as [Margin Quoted SnP],
cast(cast([[Measures]].[Revenue Converted SnP]]] as varchar(100)) as float) as [Revenue Converted SnP],
cast(cast([[Measures]].[Revenue Quoted SnP]]] as varchar(100)) as float) as [Revenue Quoted SnP],
cast(cast([[Measures]].[Units Converted SnP]]] as varchar(100)) as float) as [Units Converted SnP],
cast(cast([[Measures]].[Units Quoted SnP]]] as varchar(100)) as float) as [Units Quoted SnP],
cast(cast([[Measures]].[Margin Converted SnP]]] as varchar(100)) as float) as [Margin Converted SnP],
cast(cast([[Measures]].[Margin Quoted SnP Displays]]] as varchar(100)) as float) as [Margin Quoted SnP Displays],
cast(cast([[Measures]].[Units Quoted SnP Displays]]] as varchar(100)) as float) as [Units Quoted SnP Displays],
cast(cast([[Measures]].[Revenue Converted SnP Displays]]] as varchar(100)) as float) as [Revenue Converted SnP Displays],
cast(cast([[Measures]].[Revenue Quoted SnP Displays]]] as varchar(100)) as float) as [Revenue Quoted SnP Displays]

from openquery([AUSDWGSPOLAP1.AUS.AMER.DELL.COM],'' SELECT NON EMPTY  [Measures].[Margin Quoted SnP], [Measures].[Revenue Converted SnP], [Measures].[Revenue Quoted SnP], [Measures].[Units Converted SnP], [Measures].[Units Quoted SnP], [Measures].[Margin Converted SnP], [Measures].[Margin Quoted SnP Displays], [Measures].[Units Quoted SnP Displays], [Measures].[Revenue Converted SnP Displays], [Measures].[Revenue Quoted SnP Displays]  ON COLUMNS, NON EMPTY  ([Dimension - Account].[Account ID].[Account ID].ALLMEMBERS * [Dimension - Account].[Account Name].[Account Name].ALLMEMBERS * [Dimension - Channel].[Segment].[Segment].ALLMEMBERS * [Dimension - Account Team].[SR Badge].[SR Badge].ALLMEMBERS * [Dimension - Account Team].[SR Mgr Badge].[SR Mgr Badge].ALLMEMBERS * [Dimension - Account Team].[SR Mgr Name].[SR Mgr Name].ALLMEMBERS * [Dimension - Account Team].[SR Name].[SR Name].ALLMEMBERS * [Dimension - Fiscal Calendar].[Date].[Date].ALLMEMBERS * [Dimension - Fiscal Calendar].[Fiscal Month].[Fiscal Month].ALLMEMBERS * [Dimension - Fiscal Calendar].[Fiscal Quarter].[Fiscal Quarter].ALLMEMBERS * [Dimension - Fiscal Calendar].[Fiscal Week].[Fiscal Week].ALLMEMBERS * [Dimension - Product].[Product LOB].[Product LOB].ALLMEMBERS * [Dimension - Product].[Product Brand].[Product Brand].ALLMEMBERS * [Base - Quote Offering].[Quote Num].[Quote Num].ALLMEMBERS * [Base - Quote Offering].[Converted Flag].[Converted Flag].ALLMEMBERS * [Custom - Product SnP].[SnP LOB Level 1].[SnP LOB Level 1].ALLMEMBERS * [Custom - Product SnP].[SnP LOB Level 2].[SnP LOB Level 2].ALLMEMBERS * [Custom - Product SnP].[SnP LOB Level 3].[SnP LOB Level 3].ALLMEMBERS * [Custom - Product SnP].[SnP LOB Level 4].[SnP LOB Level 4].ALLMEMBERS * [Custom - Product SnP].[SnP LOB Level 5].[SnP LOB Level 5].ALLMEMBERS * [Custom - Product SnP].[SnP LOB Level 6].[SnP LOB Level 6].ALLMEMBERS )  DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS FROM ( SELECT (  [Dimension - Channel].[Segment].&[CBO LB Public], [Dimension - Channel].[Segment].&[CBO LB PvtEnt], [Dimension - Channel].[Segment].&[CBO MB Public], [Dimension - Channel].[Segment].&[CBO MB PvtEnt]  ) ON COLUMNS FROM ( SELECT (  [Dimension - Geography].[Country].&[United States]  ) ON COLUMNS FROM ( SELECT (  [Dimension - Fiscal Calendar].[Fiscal Month].&['+@FisMonthparam+']  ) ON COLUMNS FROM [Global SnP Quotations]))) WHERE ( [Dimension - Geography].[Country].&[United States] ) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS'')'


Exec sp_executesql @mdx

set @FisMonthloop = @FisMonthloop + 1

end

drop table tbl_CQ_snp_quotes

此查询以前运行成功,但现在开始出现以下错误,

OLE DB provider "MSOLAP" for linked server "AUSDWGSPOLAP1.AUS.AMER.DELL.COM" returned message "The XML for Analysis request timed out before it was completed.".
Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query " SELECT NON EMPTY  [Measures].[Margin Quoted SnP], [Measures].[Revenue Converted SnP], [Measures].[Revenue Quoted SnP], [Measures].[Units Converted SnP], [Measures].[Units Quoted SnP], [Measures].[Margin Converted SnP], [Measures].[Margin Quoted SnP Displays], [Measures].[Units Quoted SnP Displays], [Measures].[Revenue Converted SnP Displays], [Measures].[Revenue Quoted SnP Displays]  ON COLUMNS, NON EMPTY  ([Dimension - Account].[Account ID].[Account ID].ALLMEMBERS * [Dimension - Account].[Account Name].[Account Name].ALLMEMBERS * [Dimension - Channel].[Segment].[Segment].ALLMEMBERS * [Dimension - Account Team].[SR Badge].[SR Badge].ALLMEMBERS * [Dimension - Account Team].[SR Mgr Badge].[SR Mgr Badge].ALLMEMBERS * [Dimension - Account Team].[SR Mgr Name].[SR Mgr Name].ALLMEMBERS * [Dimension - Account Team].[SR Name].[SR Name].ALLMEMBERS * [Dimension - Fiscal Calendar].[Date].[Date].ALLMEMBERS * [Dimension - Fiscal Calendar].[Fiscal Month].[Fiscal Month].ALLMEMBERS * [Dimension - Fiscal Calendar].[Fiscal Quarter].[Fiscal Quarter].ALLMEMBERS * [Dimension - Fiscal Calendar].[Fiscal Week].[Fiscal Week].ALLMEMBERS * [Dimension - Product].[Product LOB].[Product LOB].ALLMEMBERS * [Dimension - Product].[Product Brand].[Product Brand].ALLMEMBERS * [Base - Quote Offering].[Quote Num].[Quote Num].ALLMEMBERS * [Base - Quote Offering].[Converted Flag].[Converted Flag].ALLMEMBERS * [Custom - Product SnP].[SnP LOB Level 1].[SnP LOB Level 1].ALLMEMBERS * [Custom - Product SnP].[SnP LOB Level 2].[SnP LOB Level 2].ALLMEMBERS * [Custom - Product SnP].[SnP LOB Level 3].[SnP LOB Level 3].ALLMEMBERS * [Custom - Product SnP].[SnP LOB Level 4].[SnP LOB Level 4].ALLMEMBERS * [Custom - Product SnP].[SnP LOB Level 5].[SnP LOB Level 5].ALLMEMBERS * [Custom - Product SnP].[SnP LOB Level 6].[SnP LOB Level 6].ALLMEMBERS )  DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS FROM ( SELECT (  [Dimension - Channel].[Segment].&[CBO LB Public], [Dimension - Channel].[Segment].&[CBO LB PvtEnt], [Dimens...

我是 MDX 查询的新手,因此我无法找出错误的含义。请告诉我如何解决以下错误。

【问题讨论】:

先尝试运行一个极其简单的 MDX 查询,看看是否没有连接问题。 我已经运行了其他成功运行的 mdx 查询。 @Jayant 你找到解决方案了吗? 不,我没有找到解决方案... 【参考方案1】:

对我来说似乎是超时。您可以增加此处提到的链接服务器(和 openquery)的查询超时吗? https://support.microsoft.com/en-us/kb/314530

configure 'remote query timeout', 0 go reconfigure with override go

【讨论】:

您为更改设置而运行的确切查询是什么? 我没有写查询,我只是右键单击服务器对象中的链接服务器并更改了设置。我已经运行了其他可以正常工作的 mdx 查询,但我无法找到为什么这个查询不起作用。 @Jayant 编辑了我的答案,以明确我建议的设置。在您更改该设置之前它失败了多长时间? 在我将链接服务器的查询超时时间增加到 5000 之后,它运行了 20 多分钟后失败,现在它在 30 多分钟后失败了。 忘了提到我直接在没有运行的分析服务器上运行了一个简单的查询。还有其他分析服务器,我可以从中查询数据,但是这个特定的服务器之前工作正常,但现在开始给我超时错误。【参考方案2】:

这是对您问题的替代而不是直接回答。

请尝试以下CLR 解决方案,而不是使用OPENQUERY: https://olapextensions.codeplex.com/

我们曾经有很多基于OPENQUERYmdx,并且已经开始将它们全部转移到这个CLR 存储过程中。优点是:

不需要链接服务器 字符串长度没有问题 数据类型转换容易得多。

【讨论】:

以上是关于使用 openquery 运行 MDX 查询时出现错误代码 7321的主要内容,如果未能解决你的问题,请参考以下文章

无法在链接服务器上运行 openquery

使用查询变量时出现 Gatsby 运行时错误

如何通过 saiku 直接运行 MDX 查询

使用 Criteria 运行子查询时出现 ClassCastException (String to Long)

使用 mysql2 运行大型 INSERT 查询时出现异常

使用 SEM_MATCH 函数运行查询时出现“未安装 JAVAVM”