Solved

ExecuteNonQuery and ExecuteScalar does not  return or throw an error when executing stored proc

Posted on 2009-07-04
2
362 Views
Last Modified: 2012-05-07
I have a SQLEXPRESS database.  I am using C# and ADO.net to call a stored procedure.  The SQL Stored Procedure has been tested and works as expected.

When the code executes the stored procedure is not called, there is no exception and no error.

I tried the same code with ExecuteScalar() but no difference.

Does anyone see an issue with the code below?




private void InsertTGroup(string strTEntry)

        {

            int          nRetCode = 0;

            

            // Build a connection string...
 

            SqlConnectionStringBuilder objConnString = new SqlConnectionStringBuilder();
 

            objConnString.InitialCatalog = "TGroups";

            objConnString.DataSource = @"(local)\SQLEXPRESS";

            objConnString.IntegratedSecurity = true;

            

            SqlConnection objSqlConn = new SqlConnection(objConnString.ConnectionString);
 

            using (SqlCommand objSqlCmd = 

                        new SqlCommand("InsertTGroup", objSqlConn))

            // -----------------------------------------------------------

            {

                try

                {
 

                    objSqlCmd.CommandType = CommandType.StoredProcedure;
 

                    // Input parameter
 

                    SqlParameter objSqlParam = new SqlParameter();
 

                    objSqlParam.ParameterName = "@strGroupName";

                    objSqlParam.SqlDbType = SqlDbType.NVarChar;

                    objSqlParam.Size = 120;

                    objSqlParam.SqlValue = strTEntry;

                    objSqlParam.Direction = ParameterDirection.Input;
 

                    objSqlCmd.Parameters.Add(objSqlParam);
 

                    nRetCode = objSqlCmd.ExecuteNonQuery();

                }

                catch (SqlException e)

                // -------------------------------------------------------

                {

                    Console.WriteLine(e.Message);
 

                }
 

            }
 

            objSqlConn.Close();
 

        }

Open in new window

0
Comment
Question by:MDKIMZEY
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24777503
you never open the connection:
 
SqlConnection objSqlConn = new SqlConnection(objConnString.ConnectionString);
objSqlConn.Open();  // should be inside the try catch ...

Open in new window

0
 

Author Closing Comment

by:MDKIMZEY
ID: 31599795
Thanks most kindly - looked at this for hours ...
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now