Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Database Project - Unresolved Reference to temp table

I have imported my sql server 2005 database into a VS2010 database project. One of my stored procedures contains a statement similar to

INSERT INTO #myTemp...

and Visual Studio gives me a warning such as

SQL04151: Procedure: [dbo].[mySproc] has an unresolved reference to object [#myTemp].

Is there a way of resolving this reference? I'd like to clear as many of the project warnings as possible.

like image 607
Nick Avatar asked Mar 18 '11 12:03

Nick


2 Answers

I had the same thing, where the parent creates it. Instead of getting rid of the warning by creating the table if it doesn't exist, I want to be able to throw an exception if it doesn't. Putting a CREATE statement after the return statement guarantees that it will never get ran but also clears up the warning.

IF (OBJECT_ID('tempdb..#Foo') is null)
BEGIN
    Raiserror('#Foo doesn''t exist.', 16, 1)
    RETURN
    CREATE TABLE #Foo (foo int) --Here just to get rid of compile warning
END
like image 67
Greg Biles Avatar answered Nov 13 '22 15:11

Greg Biles


Did you try three part naming as in here (VS 2010 build database project receive SQL04151)

Also you might need to change the db ref to tempdb instead of master. See this article (http://blogs.msdn.com/b/gertd/archive/2009/06/10/system-objects-in-tempdb.aspx). It describes sys objects but temporary tables are stored in tempdb so would exhibit the same behavior.

like image 36
ktharsis Avatar answered Nov 13 '22 16:11

ktharsis