Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql help 8 55
Add different cell to otherwise similiar row 4 38
SSRS 2013 - Creating a summarized report 19 33
sql 2008 how to table join 2 12
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 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