Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Odd 'Invalid object name' issue with temp tables

$
0
0
1. Run SQL Profiler with T-SQL and Errors and Warnings (Exception).2. Open a new query window in SSMS and run the following script (note the IF/DROP is not required to reproduce, just makes it easier to run the statement again):[code="sql"]IF OBJECT_ID('tempdb..#tab1', 'U') IS NOT NULL DROP TABLE #tab1; Create table #tab1 (id int)insert into #tab1 values (1)[/code][b]Expected Results:[/b]-SSMS shows query executed successfully and Messages: "(1 row(s) affected)". -SQL Profiler shows statements completes.[b]Actual Results:[/b]-SSMS shows query executed successfully and Messages: "(1 row(s) affected)". -SQL Profiler shows "Invalid object name '#tab1'" Exception prior to SQL:BatchStarting ONLY on the first time you run the statement from the query window (connection) . Run it again in the same query window and you don't get the Exception in SQL Profiler.Why is SQL throwing the exception on the first execution of the CREATE + INSERT batch, and only in SQL Profiler? I ask because this appears to be throwing an exception in an application (using LINQ). We have multiple separate instances of the application using the same SQL and the error is not thrown in all of them and when its thrown it appears at random times. This is very similar to [url=http://www.sqlservercentral.com/Forums/Topic1134908-360-1.aspx]this [/url] user's issue.

Viewing all articles
Browse latest Browse all 3145

Trending Articles