我正在运行带有 sql server 2012 的 windows server 2012 以及与 GE 的 iHistorian 的链接服务器。
如果我执行以下存储过程,则使用 2012 框中的管理工作室,我收到以下错误消息并且 sql 服务器重新启动。
从服务器接收结果时发生传输级错误。(提供者:共享内存提供者,错误:0 - 管道已结束。)
USE [Optimiser]
GO
/****** Object: StoredProcedure [dbo].[OptimiserPullDataFromHistorian] Script Date: 21/08/2013 14:15:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[OptimiserPullDataFromHistorian]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @iHistorianName varchar(32)
set @iHistorianName = 'IHISTORIAN'
declare @sqlWhere varchar(max)
set @sqlWhere='where '
declare @Tagname varchar(32)
DECLARE rsWhere CURSOR FOR
SELECT TagName FROM OptimiserTags
OPEN rsWhere
FETCH NEXT FROM rsWhere INTO @Tagname
WHILE @@FETCH_STATUS = 0
BEGIN
set @sqlWhere=@sqlWhere + ' tagname="' + @Tagname + '" or'
FETCH NEXT FROM rsWhere INTO @Tagname
END
CLOSE rsWhere
DEALLOCATE rsWhere
set @sqlWhere= left(@sqlWhere,len(@sqlWhere)-2)
declare @sqlQuery varchar(max)
declare @finalQuery varchar(max)
declare @StartDate datetime
declare @EndDate datetime
set @EndDate= {fn now()}
set @StartDate= DATEADD (hh , -1 , @EndDate )
/*
--current value
SET @sqlQuery = '
SET SamplingMode=CurrentValue,Rowcount=0,
SELECT ihtags.description as tagdescription,ihRawData.tagname, ihRawData.timestamp,
ihRawData.value, ihRawData.quality
FROM ihRawData inner join ihtags on ihtags.tagname=ihRawData.tagname
' + @sqlWhere
*/
--1 hour averages
SET @sqlQuery = '
SET SamplingMode=CurrentValue,Rowcount=0,
StartTime="' + cast(@StartDate as varchar) + '",
EndTime="' + cast(@EndDate as varchar) + '",
IntervalMilliseconds=1h,
SamplingMode=Calculated ,
calculationmode=Average,
SELECT ihtags.description as tagdescription,ihRawData.tagname, ihRawData.timestamp,
ihRawData.value, ihRawData.quality
FROM ihRawData inner join ihtags on ihtags.tagname=ihRawData.tagname
' + @sqlWhere
SET @finalQuery = '
SELECT OptimiserTags.tagname, OptimiserTags.OptimiserDescription, iHist.tagdescription,
DATEADD (n , -60 , cast(iHist.timestamp as datetime)) timestamp
, iHist.value,iHist.quality, Units, LessThanOffline, MinValue
FROM OptimiserTags
LEFT OUTER JOIN (
SELECT tagdescription, tagname, timestamp, value, quality FROM OPENQUERY
(' + @iHistorianName + ',''' + @sqlQuery + ''')
) iHist on OptimiserTags.TagName=iHist.Tagname COLLATE DATABASE_DEFAULT
ORDER BY OptimiserTags.SortOrder
'
--select @finalQuery
exec(@finalQuery)
END
如果我通过管理工作室从我的 PC 运行 SP,则没有错误消息。这是一个主要问题,因为它在 sql server 2008 上运行良好,没有任何问题。当我被谷歌搜索时,任何人都可以提供一些帮助!