Solved

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

Posted on 2009-07-04
2
365 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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