+ -
当前位置:首页 → 问答吧 → 一个一分钟执行次数达到几十万的存储过程,但是编译不通过

一个一分钟执行次数达到几十万的存储过程,但是编译不通过

时间:2011-12-06

来源:互联网

在活动监视器中检测到一条语句fetch hC into @agent_type, @agent_name, @status,一分钟执行达到几十万次,并且一直处于运行中。很是奇怪,这个语句是一个存储过程中的最后一句。
create procedure sys.sp_MSinit_replication_perfmon
as
begin
  declare @return_code int,
  @agent_type int,
  @agent_name nvarchar(100),
  @status int,
  @all_but_misc_agents int

  select @all_but_misc_agents = -1

  -- drop the temp table 
  if object_id('tempdb.dbo.#tmp_replication_status') is not null
  begin
  drop table #tmp_replication_status
  end

  -- create the temp table
  create table #tmp_replication_status
  (
  publisher sysname,
  publisher_db sysname, 
  publication sysname, 
  publication_type int,
  agent_type int, 
  status int,
  agent_id int,
  agent_name sysname,
  job_id uniqueidentifier null,
  time_stamp datetime null,
  publisher_srvid int null
  )
   
  create clustered index ctmpreplicationstatus on #tmp_replication_status (publication, publisher_db, publisher)
  create index nc1tmpreplicationstatus on #tmp_replication_status (publisher, publisher_db)
  create index nc2tmpreplicationstatus on #tmp_replication_status (agent_type)

  -- Remove all existing instances
  dbcc deleteinstance ("SQL Replication Agents", "%")
  dbcc deleteinstance ("SQL Replication Snapshot", "%")
  dbcc deleteinstance ("SQL Replication Logreader", "%")
  dbcc deleteinstance ("SQL Replication Distribution", "%")
  dbcc deleteinstance ("SQL Replication Merge", "%")
  dbcc deleteinstance ("SQL Replication Queuereader", "%")

  -- Add and initialize Perfmon SQL Replication Agents instances
  dbcc addinstance ("SQL Replication Agents", "Snapshot")
  dbcc addinstance ("SQL Replication Agents", "Logreader")
  dbcc addinstance ("SQL Replication Agents", "Distribution")
  dbcc addinstance ("SQL Replication Agents", "Merge")
  dbcc addinstance ("SQL Replication Agents", "Queuereader")
  dbcc setinstance ("SQL Replication Agents", "Running", "Snapshot", 0)
  dbcc setinstance ("SQL Replication Agents", "Running", "Logreader", 0)
  dbcc setinstance ("SQL Replication Agents", "Running", "Distribution", 0)
  dbcc setinstance ("SQL Replication Agents", "Running", "Merge", 0)
  dbcc setinstance ("SQL Replication Agents", "Running", "Queuereader", 0)

-- load tmp replication_status table
exec @return_code = sys.sp_MSload_tmp_replication_status @agent_type = @all_but_misc_agents
if @@error <> 0 or @return_code <> 0
return 1

  -- Add instances for each agent currently in the status table
  declare hC CURSOR LOCAL FAST_FORWARD for 
  select agent_type, 
  agent_name, 
  status 
  from #tmp_replication_status for read only
  open hC
  fetch hC into @agent_type, @agent_name, @status
   


大家可以编译一下,这个语句根本编译不通过,但是还一直执行,求高手指点!!!!!

作者: blue_hao   发布时间: 2011-12-06

游标还是在插值?

作者: fredrickhu   发布时间: 2011-12-06

对,一直在执行,每次检测都有,应该是24小时不停的执行

作者: blue_hao   发布时间: 2011-12-06

再一个批处理中吧,没有看到最后一个end在哪。。

作者: ssp2009   发布时间: 2011-12-06

这就是我完整的语句,最奇怪就是这里,明明语句不对,还一直在执行。在一个批处理中是什么意思?

作者: blue_hao   发布时间: 2011-12-06

游标用完了,记得要关闭及回收资源喔,
存储过程的最后少了这2句,
SQL code

 close hC
 deallocate hC




作者: ap0405140   发布时间: 2011-12-06

你的语句不全

你怎么获取这些语句的,获取方法引起被截取

作者: Haiwer   发布时间: 2011-12-06

我知道游标没有关闭,关键是所有的库中都没有这个存储过程,找不到它

语句是不全 但是为什么还会执行呢

作者: blue_hao   发布时间: 2011-12-06

这个有修改过吗?是修改后才编译不过去的吗?

作者: qqyatou   发布时间: 2011-12-06

如果是:

那个有用到这个存储过程的视图或者其他什么的,你要重新编译一下.

不重新编译,他还是会用以前的编译好的

如果不是:
 请在仔细找下原因吧

作者: qqyatou   发布时间: 2011-12-06