troubleshooting Question

VS C# Connection Property Not Been Initialized

Avatar of rwheeler23
rwheeler23Flag for United States of America asked on
.NET ProgrammingC#
9 Comments2 Solutions449 ViewsLast Modified:
I have upgraded a program from VS C# 2008 to VS C# 2010. It is now set for .Net FW 3.5 where before it was .Net 2.0

When I run the code and this routine is called, I am now getting the message "Connection Property Has Not Been Initialized" on the cmd.ExecuteNonQuery() line. I tried inserting cmd.Connection.Open() before the execute but then I get "Object has not been set to an instance of an object" message. It appears something is different. How do I structure this code so the sp will fire?

private void InsertReasonForChange()
                SqlCommand cmd = new SqlCommand();

                /* Insert/Update the reason for the sell price change */
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@SOPNUMBE", SOPNUMBE));
                cmd.Parameters.Add(new SqlParameter("@SOPTYPE", SOPTYPE));
                cmd.Parameters.Add(new SqlParameter("@LNITMSEQ", LNITMSEQ));
                cmd.Parameters.Add(new SqlParameter("@CMPSEQNM", CMPSEQNM));
                cmd.Parameters.Add(new SqlParameter("@USERID", GP_User_ID));
                cmd.Parameters.Add(new SqlParameter("@REASON", txtReason.Text));

                cmd.CommandText = "rbs_ChangeSellPriceReason";

                cmd.Connection = DataConnection;
            catch (Exception ex)
                string eMsg = "003: ERROR: " + ex.Message;
                if (stackTraceWanted) eMsg += "\n" + ex.StackTrace;
                if (stackTraceWanted) MessageBox.Show(eMsg);
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros