Link to home
Start Free TrialLog in
Avatar of MDKIMZEY
MDKIMZEYFlag for United States of America

asked on

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))
            // -----------------------------------------------------------
            {
                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

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MDKIMZEY

ASKER

Thanks most kindly - looked at this for hours ...