简体   繁体   English

临时表在SSIS中立即下降

[英]Temp Table Dropped Immediately in SSIS

I have successfully deployed many SSIS packages (in SQL Server 2008 R2). 我已经成功部署了许多SSIS包(在SQL Server 2008 R2中)。

I have discovered an issue that is stumping me. 我发现了一个困扰我的问题。 Examine the basic following flow. 检查以下基本流程。

在此输入图像描述

In 'Download Files from FTP' I pick up the new files I want to operate on and download them to my local drive, saving the picked up files so they can be iterated upon in the Process Each File foreach container. 在“从FTP下载文件”中,我选择了我想要操作的新文件并将其下载到我的本地驱动器,保存拾取的文件,以便可以在Process Each File foreach容器中进行迭代。

In 'Create Temp Table' I am creating a temp table as such: 在“创建临时表”中,我将这样创建一个临时表:

IF not exists (SELECT * FROM tempdb.dbo.sysobjects WHERE name='##tempProcessFiles' and xtype='U')
CREATE TABLE ##tempProcessFiles
(
--my columns
)
GO

In 'Truncate Temp Table' I am doing: 在'Truncate Temp Table'中,我正在做:

TRUNCATE TABLE ##tempProcessFiles

Basically, I pick up some files, create a temp table and then loop through each file, loading the necessary junk to my database. 基本上,我会拾取一些文件,创建一个临时表,然后遍历每个文件,将必要的垃圾加载到我的数据库中。 In order to make sure everything runs smoothly, I truncate the temp table on each iteration so I have a fresh table to work with. 为了确保一切顺利进行,我在每次迭代时都截断了temp表,以便可以使用一个新表。 On the very last step of this package, I drop the temp table. 在该程序包的最后一步,我删除了临时表。 I also drop the temp table OnError. 我也删除临时表OnError。

The problem is, when I schedule this guy, create temp table executes fine but once it reaches 'truncate temp table', it throws an exception saying the temp table does not exist. 问题是,当我安排这个人时,创建临时表执行正常,但一旦达到'truncate temp table',它会抛出一个异常,说临时表不存在。 Specifically: 特别:

Executing the query "TRUNCATE TABLE ##tempProcessFiles" failed with the following error: "Cannot find the object "##tempProcessFiles" because it does not exist or you do not have permissions.". 执行查询“ TRUNCATE TABLE ## tempProcessFiles”失败,并出现以下错误:“找不到对象“ ## tempProcessFiles”,因为它不存在或您没有权限。”。 Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly. 可能的故障原因:查询问题,“ResultSet”属性设置不正确,参数设置不正确或连接未正确建立。

Running this package in debug mode does not recreate this scenario. 在调试模式下运行此程序包不会重新创建此方案。 Everything works fine. 一切正常。

I discovered (after many days of frustration, chasing ideas that sent me in circles) that by removing the GO statement in 'Create Temp Table' my package would execute normally. 我发现(经过多天的挫折之后,追逐那些让我圈起来的想法),通过删除“创建临时表”中的GO语句,我的包将正常执行。

It was determined that there were no errors or no accidental dropping of my temp table. 确定我的临时表没有错误或意外删除。 Plus, I had persist security info set to false like always, delay validation set to true like always; 另外,我一直坚持将安全信息设置为false,将验证设置为始终为true; but my drop temp table task wasn't firing - I even tried deploying it with it disabled. 但是我的drop temp table任务没有解雇 - 我甚至尝试将它部署,并禁用它。 None of my other packages used this global temp table and the database had no scheduled jobs or triggers dropping it or anything ridiculous like that. 我的其他软件包都没有使用此全局临时表,并且数据库没有计划的作业或触发器来删除它或类似的东西。

All I can determine is that the GO operator here was causing my session to the database to terminate and cause my temp table to be dropped immediately. 我可以确定的是,这里的GO运算符导致我的数据库会话终止并导致我的临时表立即被删除。 Is this how GO operators works in SSIS? 这是GO运营商在SSIS中的运作方式吗? If I were to run a script on SQL Server using the exact same syntax as I have in my package, I definitely would not experience this kind of thing, so it's thrown me for a loop. 如果我使用与我的包中完全相同的语法在SQL Server上运行脚本,我肯定不会遇到这种情况,所以它抛出了我的循环。 But I'm not a DBA, so it's probably something fundamental or subtle to that area of work. 但是我不是DBA,所以这可能是该工作领域的基础或微妙之处。

Can anyone explain what really happened here? 谁能解释一下这里发生了什么? Or would I need to provide more detail about my package to get a sufficient answer? 还是我需要提供有关包裹的更多详细信息以获得足够的答案? The only change I did was removing GO from 'Create Temp Table', so that was the definite fix. 我所做的唯一更改是从“创建临时表”中删除了GO,因此这是确定的解决方法。

It seems that the connection is being dropped after all, despite RetainSameConnection . 尽管RetainSameConnection ,似乎连接正在被删除。 To gather more information, try following: 要收集更多信息,请尝试以下操作:

Run a trace while executing the package to confirm the above (add Security Audit > Login/Logout and Sessions > Existing connections). 在执行软件包时运行跟踪以确认以上内容(添加安全审核>登录/注销和会话>现有连接)。 Pay attention to StartTime and EndTime, maybe it'll be something interesting like 30s (default command timeout)? 注意StartTime和EndTime,也许它会像30s一样有趣(默认命令超时)?

Then try running this package with Crate and Truncate tasks only (without the loop) to eliminate a possibility that other components are interfering (Data Sources using same Connection Manager?). 然后尝试仅使用Crate和Truncate任务运行该程序包(无循环),以消除其他组件相互干扰的可能性(使用相同的Connection Manager的数据源?)。 If it works, try it with a loop, but with Truncate task only placed inside, and keep adding other components. 如果它工作,尝试循环,但只有Truncate任务放在里面,并继续添加其他组件。

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

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