Could not find stored procedure


I am getting SQL Exception when calling stored procedure in my asp.net MVC the exception is : "Could not find stored procedure"

 

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using Event_Recommendation_App.Models;

namespace Event_Recommendation_App.ViewModel.Home
{
public class Signup_ViewModel
{
public List<Signup> GetAllSignup()
{
List<Signup> Signupp = new List<Signup>();
string connstring = ConfigurationManager.ConnectionStrings["dbx"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connstring))
{
using (SqlCommand cmd = new SqlCommand("usp_SignupGetAll", conn))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;

conn.Open();

SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Signup signups = new Signup();
signups.id = Convert.ToInt16(reader["id"]);
signups.email = Convert.ToInt16(reader["email"]).ToString();
signups.password = Convert.ToInt16(reader["password"]).ToString();

Signupp.Add(signups);
}

}
}

return Signupp;
}

public void InsertSignup(Signup signup)
{
string connstring = ConfigurationManager.ConnectionStrings["dbx"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connstring))
{
using (SqlCommand cmd = new SqlCommand("usp_SignupGetAll", conn))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;          // Here exception occurs.

conn.Open();
cmd.Parameters.AddWithValue("@email", signup.email);
cmd.Parameters.AddWithValue("@password", signup.password);

cmd.ExecuteNonQuery();

}
}
}
}
}

Asked by:- MuhammadFaizan
1
: 6814 At:- 7/18/2017 10:51:15 AM
asp.net exception sql exception stored-procedure

Can you show the image or code for error stack trace? you can update your question 0
By : vikas_jk - at :- 7/18/2017 11:06:38 AM






3 Answers
profileImage Answered by:- neena

There are 2 causes:

1- store procedure name When you declare store procedure in code make sure you do not exec or execute keyword for example:

C#

string sqlstr="sp_getAllcustomers";// right way to declare it.

string sqlstr="execute sp_getAllCustomers";//wrong way and you will get that error message.

From this code:

MSDBHelp.ExecuteNonQuery(sqlconexec, CommandType.StoredProcedure, sqlexec);

CommandType.StoreProcedure will look for only store procedure name and ExecuteNonQuery will execute the store procedure behind the scene.

2- connection string:

Another cause is the wrong connection string. Look inside the connection string and make sure you have the connection especially the database name and so on.

Check if you are using Windows Authentication or SQL Server authetication

1
At:- 7/18/2017 11:22:55 AM


profileImage Answered by:- vikas_jk

Your Stored procedure call should be like:

using (SqlConnection conn = new SqlConnection("Server=(local);DataBase=Northwind;Integrated Security=SSPI")) {
    conn.Open();

    // 1.  create a command object identifying the stored procedure
    SqlCommand cmd  = new SqlCommand("usp_SignupGetAll", conn);

    // 2. set the command object so it knows to execute a stored procedure
    cmd.CommandType = CommandType.StoredProcedure;

    // 3. add parameter to command, which will be passed to the stored procedure
   
cmd.Parameters.AddWithValue("@email", signup.email);
cmd.Parameters.AddWithValue("@password", signup.password);

cmd.ExecuteNonQuery();
    }
}

Links to help you

1
At:- 7/18/2017 11:37:06 AM Updated at:- 7/18/2017 11:38:48 AM


profileImage Answered by:- bhanu

If you are using SQL Server Management Studio and getting this issue, you can try to refresh local cache of SSMS

"Edit"->"Intellisense"-> "Refresh local cache" (Not: you will only see this menu when you have tried to execute some SP or Query)

refresh-local-cache-min.png

0
At:- 3/25/2021 8:55:07 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use