Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
cmd.ExecuteNonQuery(); is returning an execption Could not find stored procedure.... but It is there


C#
#region AddBus
public int Addbus(BusinessObject.BusinessObject objbo)
{
    //Create Connection
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
    //Open the Connection
    con.Open();
    //pass the procedure
    SqlCommand cmd = new SqlCommand("proc_addbus",con);
    cmd.CommandType = CommandType.StoredProcedure;

    cmd.Parameters.AddWithValue("@svno",objbo.ServiceNo);
    cmd.Parameters.AddWithValue("@fromplace",objbo.FromPlace);
    cmd.Parameters.AddWithValue("@toplace",objbo.Toplace);
    cmd.Parameters.AddWithValue("@capacity",objbo.capacity);
    cmd.Parameters.AddWithValue("@arrtime",objbo.ArriTime);
    cmd.Parameters.AddWithValue("@depttime",objbo.DeptTime);
    cmd.Parameters.AddWithValue("@tname",objbo.TrevalAgnName);
    cmd.Parameters.AddWithValue("@bustype",objbo.BusType);
    int i = cmd.ExecuteNonQuery();
    return i;

}
#endregion
Posted
Comments
ZurdoDev 6-Jan-16 11:38am    
1. Double check your connection string to make sure you're looking at the same db. That error is only shown for one reason.
2. Your SQL could be case sensitive so make sure proc_addbus is exact.
[no name] 6-Jan-16 18:28pm    
+5 unfortunately useless for you :(
ZurdoDev 7-Jan-16 7:08am    
It's the thought that counts. ;)

1 solution

Things to check:
- does the connection string point to correct database
- does the user defined for the connection have privileges to view and execute the procedure
- is the owner of the procedure dbo or someone else. Do you need to specify the schema
- is the database case sensitive and is the casing of the procedure name provided correctly.
 
Share this answer
 
Comments
[no name] 6-Jan-16 18:26pm    
A 5 for this.
Wendelius 8-Jan-16 1:35am    
Thank you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900