Solved

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

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

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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