Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all;
I am calling a stored procedure from a c# program and I keep having this error message :
'could not find the stored procedure sp_Trial'

C# codes are as follows
-----------------------
C#
protected void btn_Add_Click1(object sender, EventArgs e)
{

try
{

// Connection to the database
//
//
string str;
str = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
SqlConnection sqlCon = new SqlConnection(str);

// Call the stored procedure
SqlCommand sqlCmd = new SqlCommand("sp_Trial", sqlCon);
sqlCmd.CommandType = System.Data.CommandType.StoredProcedure;

// Create and supply the output parameters
sqlCmd.Parameters.Add("@LoanID", System.Data.SqlDbType.VarChar, 10);
sqlCmd.Parameters["@LoanID"].Direction = System.Data.ParameterDirection.Output;


// Open the sql data connection
sqlCon.Open();

// Execute the stored procedure
sqlCmd.ExecuteNonQuery();

lblstatus.Text = "Student details saved successfully";

// Assign the results to the controls
txt_Int_Code.Text = sqlCmd.Parameters["@LoanID"].Value.ToString();

//
//
sqlCon.Close();

}

catch (Exception ex)
{
lblstatus.Text = ex.Message;
}

Stored Procedure
-----------------
SQL
USE [COC_CREDIT]
GO
/****** Object: StoredProcedure [dbo].[sp_Trial] Script Date: 05/25/2014 12:22:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER Procedure [dbo].[sp_Trial]
(
@LoanID	varchar(10) Output
)
As
Begin

Declare @SID Smallint

Select @SID = ISNULL(MAX(CONVERT(SMALLINT,SUBSTRING(INT_NO,4,6))),0) + 1 From INTEREST

Select @LoanID = 'INT' + REPLICATE('0',6 - LEN(@SID)) + CONVERT(VARCHAR(6),@SID)
End

Please help me to correct the error
Posted
Updated 25-May-14 2:46am
v2
Comments
Kornfeld Eliyahu Peter 25-May-14 8:49am    
Probably your connection string points to some other database...
Check it again!

1 solution

Check your connection string: then check the database that it refers to. Chances are that you have updated the production database to have the SP and not the development DB, or vice versa.
 
Share this answer
 

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