Solved

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

Posted on 2009-07-04
2
369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

762 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