12

I have a stored procedure that I'm using in a dataset to generate a report in ReportViewer.

This SP uses temporary tables to store intermediate values, so that these can be used in a calculation at the end of the SP.

The temp tables are all dropped cleanly at the end of the SP.

I can execute the SP in SSMS with no issues and it returns the data that I expect.

However, when use the TableAdapter Configuration Wizard to update my xsd in VS2012, it gives me the error Invalid object name '#Held' (where #Held is the name of one of the temp tables).

What's going on?

1

2 Answers 2

28

The answer stated here works perfectly, for reasons unknown.

Just place the below code after the stored procedure after the AS part of the SP.

IF 1=0 BEGIN
    SET FMTONLY OFF
END
3
  • Worked like a charm. FMTONLY returns only metadata to the client. Can be used to test the format of the response without actually running the query. Commented Jun 21, 2017 at 7:38
  • You are my hero right now Bat. I've been banging my head against the wall for the past 2 hours trying to figure out why temp tables in an SP cause the TableAdapter Config Wizard to fail.
    – John Baker
    Commented Sep 27, 2017 at 18:21
  • 1
    years later you saved someone's day today, know that. :) Commented Jul 12, 2019 at 15:15
2

There's some known issues with #temp tables and table adapters.

Some people have got around it by explicitly selecting column names, eg:

SELECT column1, column2, ... from #temptable rather than SELECT * (if you are doing that)

You could also try using a table variable rather than a temp table.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.