﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » ExecuteNonQuery issue with creating Temp Table</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 00:03:02 GMT</lastBuildDate><ttl>20</ttl><item><title>ExecuteNonQuery issue with creating Temp Table</title><link>http://forum.strataframe.net/FindPost25843.aspx</link><description>I keep getting the following error whenever i try to access a temp table that was created using the ExecuteNonQuery method:&lt;br&gt;
&lt;br&gt;
Invalid object name '#tList'.&lt;br&gt;
&lt;br&gt;
I have the code within a data retrieval method of a BO.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
[codesnippet]&lt;br&gt;
            this.FillDataTable(cmd);&lt;br&gt;
&lt;br&gt;
            if (this.MoveFirst())&lt;br&gt;
            {&lt;br&gt;
                this.ExecuteNonQuery("CREATE TABLE #tList (poitemsextended_pk int, po_no varchar(10), part_no varchar(30))");&lt;br&gt;
&lt;br&gt;
                SqlCommand tcmd = new SqlCommand();&lt;br&gt;
                do&lt;br&gt;
                {&lt;br&gt;
&lt;br&gt;
                    tcmd.CommandText = "INSERT INTO #tList (poitemsextened_pk, po_no, part_no) VALUES (@poitemsextended_pk, @po_no, @part_no)";&lt;br&gt;
&lt;br&gt;
                    int poiepk = this.CurrentRow["PoIEpk"] == DBNull.Value ? 0 : (int)this.CurrentRow["PoIEpk"];&lt;br&gt;
&lt;br&gt;
                    tcmd.Parameters.AddWithValue("@poitemsextended_pk", poiepk).SqlDbType = SqlDbType.Int;&lt;br&gt;
                    tcmd.Parameters.AddWithValue("@po_no", this.po_no).SqlDbType = SqlDbType.VarChar;&lt;br&gt;
                    tcmd.Parameters.AddWithValue("@part_no", this.part_no).SqlDbType = SqlDbType.VarChar;&lt;br&gt;
&lt;br&gt;
                    this.ExecuteNonQuery(tcmd);&lt;br&gt;
&lt;br&gt;
                } while (this.MoveNext());&lt;br&gt;
&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
The error is returned on this.ExecuteNonQuery(tcmd) at the end.&lt;br&gt;
&lt;br&gt;
I've tried passing the insert as a string instead of an SqlCommad but i get the same error. I've also tried creating a global table prefixing tList with ## with same results.&lt;br&gt;
&lt;br&gt;
Any help would be greatly appreciated.</description><pubDate>Tue, 09 Feb 2010 07:56:29 GMT</pubDate><dc:creator>Victor Sousa</dc:creator></item><item><title>RE: ExecuteNonQuery issue with creating Temp Table</title><link>http://forum.strataframe.net/FindPost25858.aspx</link><description>Sounds good, let us know if you have any questions as you move forward. :)</description><pubDate>Tue, 09 Feb 2010 07:56:29 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: ExecuteNonQuery issue with creating Temp Table</title><link>http://forum.strataframe.net/FindPost25856.aspx</link><description>Thanks again Trent. I will follow the SPROC path.</description><pubDate>Tue, 09 Feb 2010 07:43:04 GMT</pubDate><dc:creator>Victor Sousa</dc:creator></item><item><title>RE: ExecuteNonQuery issue with creating Temp Table</title><link>http://forum.strataframe.net/FindPost25853.aspx</link><description>Victor,&lt;br&gt;
&lt;br&gt;
Well, technically, a new session is created when a connection is opened. When a connection is closed, then that session ceases to exists and thus the temp tables with them. Now you could try a global temp table using the ## instead of the #, but you may run into the same issue and there is some danger of other users hitting the temp table. There are quit a few articles out on the web about this, but the one thing that I know and have proven time and time again is that if you close a connection, which a BO does after each data layer call, the temp tables will go with it.&lt;br&gt;
&lt;br&gt;
The reason that you do not want to keep a connection open is actually very simple and easy to reproduce....performance! When you keep a connection open, you have a quick descent on performance as well as resources. So a I mentioned previously, you are better off creating a SPROC to handle this.&lt;br&gt;
&lt;br&gt;
FYI, VFP handles temp tables and SQL passthroughs entirely differently than .NET (as does the Jet OLEDB provider if you are using Access).</description><pubDate>Tue, 09 Feb 2010 07:04:11 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: ExecuteNonQuery issue with creating Temp Table</title><link>http://forum.strataframe.net/FindPost25849.aspx</link><description>Thanks for the quick reply Trent.  I thought the SQL temp tables persisted through the same SQL session ID. I have used the same sort of calls with success from VFP with SQL Passthrough. I viewed the Activity Monitor from within SQL management studio as my strataframe app ran, and it appears that the same session id is being used throughout my calls. Is that not the case? Is my understanding of the temp tables per session flawed?&lt;br&gt;
&lt;br&gt;
thanks again.</description><pubDate>Mon, 08 Feb 2010 22:41:33 GMT</pubDate><dc:creator>Victor Sousa</dc:creator></item><item><title>RE: ExecuteNonQuery issue with creating Temp Table</title><link>http://forum.strataframe.net/FindPost25844.aspx</link><description>It looks as though you are trying to access a temp table between two calls.&amp;nbsp; A temp table only lasts as long as a connection is active.&amp;nbsp; As soon as a connection is killed, so is the temp table.&amp;nbsp; This is actually outside of the StrataFrame environment and pertains to how SQL Server treats a temp table and a live connection.&lt;/P&gt;&lt;P&gt;You are better off creating a stored procedure to encapsulate this logic so that you can do exactly what you want.&amp;nbsp; I use temp tables quite a bit and so this is sound logic.&amp;nbsp; A good example is when working within the SQL Server Management Studio.&amp;nbsp; When you create a temp table and do not close it, then run it again, you will get an error indicating that the table still exists.&amp;nbsp; However, if you close the session (which closes the connection), and then try again without having actually dropped the temp table, you will notice there is not an error.&amp;nbsp; This is because the temp tables are dropped automatically when a connection is closed.&lt;/P&gt;&lt;P&gt;Hope that makes sense.&amp;nbsp; :)</description><pubDate>Mon, 08 Feb 2010 21:01:21 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item></channel></rss>