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

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))
            // -----------------------------------------------------------
                    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;
                    nRetCode = objSqlCmd.ExecuteNonQuery();
                catch (SqlException e)
                // -------------------------------------------------------

Open in new window

Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
you never open the connection:
SqlConnection objSqlConn = new SqlConnection(objConnString.ConnectionString);
objSqlConn.Open();  // should be inside the try catch ...

Open in new window

MDKIMZEYAuthor Commented:
Thanks most kindly - looked at this for hours ...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.