We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,687 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Global Temp Table issue

I am attempting to create a global temp table to be used between two sessions being called from a webservice.

When I attempt to access the temp table from the second session it can not be found. The reason I am using a global temp table is because the initial session is created on a before event handler which calls the service and then from an after event handler.

I have checked that the table is still available after the initial session closes, and I am still able toe query the data.

Any help would be greatly appreciated!

public void SetUpdateHolds(string SOPnumber, int SOPType, string companyId, string compDatabaseName)
            {
                
                
                SqlConnection conn = new SqlConnection(connString.StrEPConnString);
                conn.Open();
                

                try
                    {


                        string sql = " USE [" + compDatabaseName + "]" +
                                     "CREATE TABLE ##HOLDS (HOLDID varchar (20)) ";
                                     
                        SqlCommand command = conn.CreateCommand();
                        command.CommandText = sql;
                        command.ExecuteNonQuery();
                        
                        sql = 
                                "INSERT INTO ##HOLDS " +
                                "SELECT PRCHLDID from SOP10104 WHERE SOPNUMBE = '" + SOPnumber + "' AND DELETE1 = '0' AND  SOPTYPE ='" + SOPType + "'";


                        command.CommandText = sql;
                        command.ExecuteNonQuery();
                        command.Dispose();
                        conn.Close();
                        conn.Dispose();
          
                    }
                    catch (SqlException e)
                    {

                        util.Log("Error creating temp table after canceling RemoveHold " + SOPnumber + e.Message + e.StackTrace);
                        conn.Close();
                        conn.Dispose();
                       
                    }

            }

            public void UpdateHolds(string SOPnumber, int SOPType, string companyId, string compDatabaseName)
            {

                Collection<CCTransaction> list = new Collection<CCTransaction>();
                SqlConnection conn = new SqlConnection(connString.StrEPConnString);
                conn.Open();
                string result = "";


                try
                {

                    string sql = "USE [" + compDatabaseName + "] UPDATE SOP10104 SET DELETE1 = 0 WHERE PRCHLDID = (SELECT  HOLDID FROM ##HOLDS)";
                                 
                           

                    SqlCommand command = conn.CreateCommand();
                    command.CommandText = sql;
                    SqlDataReader reader = command.ExecuteReader();
                    command.ExecuteNonQuery();
                 
                           
                    sql = "DROP TABLE ##HOLDS"; 

                    
                    command.ExecuteNonQuery();
                    command.Dispose();
                    conn.Close();
                    conn.Dispose();

                }
                catch (SqlException e)
                {

                    util.Log(result + "   Error  updating PRCHLDID in Table SOP10104 after canceling RemoveHold " + SOPnumber + e.Message + e.StackTrace);
                    conn.Close();
                    conn.Dispose();

                }




            }
2
Contributors
1
Reply
21 Hours
Discussion Span
1 Year Ago
Last Updated
2
Views
Mike_
Newbie Poster
1 post since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You need to call new on your new SQL commands.
Also, don't you get an Exception or an invalid state when the code hits the ExecuteReader followed by the ExecuteNonQuery?

thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0554 seconds using 2.66MB