Answered Stored procedure problems

kwhelchel

Well-known member
Joined
Feb 28, 2020
Messages
53
Programming Experience
Beginner
created a stored procedure in ssms 2019

C#:
CREATE PROCEDURE usp_Close
AS
    
    BEGIN

        SELECT [closeid], [e_date]
        FROM   [dbo].[close1]


    END

which ran find and I see my procedure in ssms, but when i go to test i get this when trying to pull up the sql data in a listbox
System.Data.SqlClient.SqlException: 'Could not find stored procedure '/*usp_Close*/'.'
the code for the listbox is as
C#:
        private DataTable GetData()
        {
            DataTable Close = new DataTable();
            string connectionString = ConfigurationManager.ConnectionStrings["VersiReports_V1.Properties.Settings.versiposConnectionString"].ConnectionString;
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand("/*usp_Close*/", conn))
                {
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                Close.Load(reader);

            }

so not sure what I did wrong yet
 
created a stored procedure in ssms 2019

C#:
CREATE PROCEDURE usp_Close
AS
   
    BEGIN

        SELECT [closeid], [e_date]
        FROM   [dbo].[close1]


    END

which ran find and I see my procedure in ssms, but when i go to test i get this when trying to pull up the sql data in a listbox
System.Data.SqlClient.SqlException: 'Could not find stored procedure '/*usp_Close*/'.'
the code for the listbox is as
C#:
        private DataTable GetData()
        {
            DataTable Close = new DataTable();
            string connectionString = ConfigurationManager.ConnectionStrings["VersiReports_V1.Properties.Settings.versiposConnectionString"].ConnectionString;
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand("/*usp_Close*/", conn))
                {
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                Close.Load(reader);

            }

so not sure what I did wrong yet
When you're calling the stored procedure you're actually passing it a sql comment which means Sql Server wont process anything, if you change your SqlCommand to do "Exec
usp_Close;" I'm sure you'll see it actually run the query in the procedure.
 
Look at your line #7:
C#:
SqlCommand cmd = new SqlCommand("/*usp_Close*/", conn)

Why are you passing in "/*usp_Close*/" ? @JuggaloBrotha is suggesting that you pass in something else like "Exec usp_Close".
 
using (SqlCommand cmd = new SqlCommand("/*usp_Close*/", conn))
Multi-line comments start with /* and end with */
 
For future reference, please provide select a prefix of Question when posting a question and then change it to Answered when your question is answered. That will save people opening your thread and reading the whole thing, only to discover that the problem has been solved.
 
Back
Top Bottom