简体   繁体   English

Visual Studio 2019 和 SQL Server 2019 - 临时表不可见,但 SQL 表示它们已经存在

[英]Visual Studio 2019 and SQL Server 2019 - Temp tables not visible but SQL says they already exist

I recently upgraded my SQL Server and Visual Studio IDE to the 2019 versions.我最近将我的 SQL 服务器和 Visual Studio IDE 升级到 2019 版本。 Have run into some new behaviors and can't find a solution to my problem.遇到了一些新行为,无法找到解决我的问题的方法。 I was creating a stored proc in VS that uses local temp tables and hit an error that stopped the debugger.我在 VS 中创建了一个使用本地临时表的存储过程,并遇到了停止调试器的错误。 I was expecting VS to auto-close and delete the temp tables so that once the bug was fixed, I could continue working.我期待 VS 自动关闭并删除临时表,以便修复错误后,我可以继续工作。 Apparently, this didn't happen as once I restarted the SQL debugger it complained that the temp tables already existed.显然,这并没有发生,因为一旦我重新启动 SQL 调试器,它就会抱怨临时表已经存在。 I went looking in the tempdb database for them, they're not there, but I continue getting this message.我在 tempdb 数据库中查找它们,它们不存在,但我继续收到此消息。

I've done the usual stuff, wrote a query to list the temp tables by name, nothing shows up.我已经完成了通常的工作,编写了一个查询以按名称列出临时表,但没有显示任何内容。 Searched by ObjectID and nothing.按 ObjectID 搜索,什么也没有。 Closed my connection and exited VS, restart and the problem persists.关闭我的连接并退出VS,重新启动,问题仍然存在。 I even rebooted SQL Server thinking some maint tasks might cleanup the temp tables.我什至重新启动了 SQL 服务器,认为一些维护任务可能会清理临时表。 No luck.没运气。

Since they were local temp tables with names like #table1 #table2 and I was logged into my domain with an Admin account, I changed the query to use global temp tables with names like ##table1, ##table2.由于它们是名称如#table1 #table2 的本地临时表,并且我使用管理员帐户登录到我的域,因此我将查询更改为使用名称如##table1、##table2 的全局临时表。 Restarted the SP again and still, it complains the tables exist.再次重新启动 SP,它仍然抱怨表存在。 So I logged in to SQL server as admin and went looking again in the tempdb, there's nothing there except what SQL server uses for its own work.所以我以管理员身份登录到 SQL 服务器并再次在 tempdb 中查看,除了 SQL 服务器用于自己的工作之外,什么都没有。

Thinking I could solve this problem by simply using altogether different names for my temp tables, I changed my SP, restarted the debugger and low and behold, it tells me these temp tables, now with different names on a 1st-time use, already exist.以为我可以通过简单地为我的临时表使用完全不同的名称来解决这个问题,我更改了我的 SP,重新启动了调试器,然后看,它告诉我这些临时表,现在在第一次使用时具有不同的名称,已经存在.

Now I'm feeling a little paranoid like my server knows what I'm thinking and is screwing with me for giggles and grins.现在我感觉有点偏执,就像我的服务员知道我在想什么,并且为了咯咯笑和笑容而与我开玩笑。 I'm out of ideas and could use a helping hand.我没有想法,可以伸出援助之手。 WTF is going on that new table names on first use would come back as already existing? WTF 正在进行第一次使用时的新表名将恢复为已经存在?

The code looks like this for each of the 3 temp tables. 3 个临时表中的每一个的代码如下所示。

CREATE TABLE #MsgFailureLogs
(
    [SourceLogId] [int] NULL,
    [SmtpConversationId] [int] NULL,
    [SmtpExLogId] [int] NULL,
    [SmtpDebugId] [int] NULL,
    [HostIp] [varchar](25) NULL,
    [HostName] [varchar](150) NULL,
    [HostDomain] [varchar](150) NULL,
    [Socket] [int] NULL,
    [ClientIp] [varchar](25) NULL,
    [ResponseCode] [varchar](50) NULL,
    [Explanation] [varchar](500) NULL,
    [MsgDate] [datetime] NULL,
    [LogEntryType] [varchar](50) NULL,
    [MsgID] [varchar](50) NULL,
    [Message] [varchar](500) NULL,
    [ErrorCode] [varchar](25) NULL,
    [LineNumber] [int] NOT NULL,
);

Thanks in advance.提前致谢。

I've solved my problem but can't explain why at the moment.我已经解决了我的问题,但目前无法解释原因。 I commented out the create temp table syntax on 2 of the larger temp tables, the 3rd has only 1 field and int.我在 2 个较大的临时表上注释掉了 create temp table 语法,第三个只有 1 个字段和 int。 Ran the sql query without these predefined table structures and it didn't complain about temp tables already exists.在没有这些预定义表结构的情况下运行 sql 查询,它没有抱怨临时表已经存在。 Funny thing is, that 3rd table with a single int field, is predefined in code.有趣的是,具有单个 int 字段的第三个表是在代码中预定义的。 All tables use either a SELECT INTO or an INSERT INTO.所有表都使用 SELECT INTO 或 INSERT INTO。 Why the interpreter doesn't complain about 1 table but does on the others, is a mystery for now.为什么口译员不抱怨一张桌子而是抱怨其他桌子,现在还是个谜。 I've been working with LINQ forever, so I'm guessing this is new behavior for SQL 2019 or VS 2019. That or I've simply forgotten such details over the years.我一直在使用 LINQ,所以我猜这是 SQL 2019 或 VS 2019 的新行为。或者我多年来只是忘记了这些细节。 Thanks for the feedback.感谢您的反馈。

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

相关问题 使用 SQL Server 2019/Visual Studio 2019 创建 SSIS package - Create SSIS package with SQL Server 2019/Visual Studio 2019 SSIS Visual Studio 2019 用于 SQL 服务器 2008 - SSIS Visual Studio 2019 for SQL Server 2008 Visual Studio 2019 缺少 SQL 服务器 - Visual Studio 2019 missing SQL Server Visual Studio 2019 中的 SQL Server 数据库项目功能 - SQL Server database project functionality In Visual Studio 2019 无法使用服务器资源管理器在 SQL Server 2019 和 Visual Studio 2019 之间添加数据连接 - Unable to add data connection between SQL Server 2019 and Visual Studio 2019 with Server Explorer 如何从 Visual Studio 2019 调试 SQL - How to debug SQL from Visual Studio 2019 Visual Studio 2019 c-sharp 中检索 SQL Server 2019 表列列表的 ExecuteScalar 方法错误地按 ASCII 排序 - ExecuteScalar method to retrieve SQL Server 2019 table column list in Visual Studio 2019 c-sharp is incorrectly ASCII sorted Visual Studio 2019 中的 SQL 查询生成器不读取 PL/SQL - SQL Query Builder in Visual Studio 2019 does not read PL/SQL 将我的多维数据集从 Visual Studio 2019 部署到 SQL Server Management Studio 中的 SSAS 时遇到问题 - I have a problem while deploying my cube from Visual Studio 2019 to SSAS in SQL Server Management Studio 如何在 Visual Studio 2019 中将表和数据导入 SQL Server 数据库项目 - How to import Table and Data to SQL Server Database Project in Visual Studio 2019
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM