Click here to Skip to main content
15,901,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created a stored procedure and when I implement in coding but got an error....

I wrote a code


C#
SqlConnection conn;
            SqlCommand comm;
            string connectionString = ConfigurationManager.ConnectionStrings["Dorknozzle"].ConnectionString;
            conn = new SqlConnection(connectionString);
            comm = new SqlCommand("InsertHelpDesk1", conn);
            comm.CommandType = System.Data.CommandType.StoredProcedure;


comm.Parameters.Add("@EmployeeID", System.Data.SqlDbType.Int,50);
           comm.Parameters["@EmployeeID"].Value = 5;
           comm.Parameters.Add("@StationNumber", System.Data.SqlDbType.Int);
           comm.Parameters["@StationNumber"].Value = stationTextBox.Text;
           comm.Parameters.Add("@CategoryID", System.Data.SqlDbType.Int);
           comm.Parameters["@CategoryID"].Value = categorylist.SelectedItem.Value;
           comm.Parameters.Add("@SubjectID", System.Data.SqlDbType.Int);
           comm.Parameters["@SubjectID"].Value = subjectlist.SelectedItem.Value;
           comm.Parameters.Add("@Description", System.Data.SqlDbType.NVarChar, 50);
           comm.Parameters["@Description"].Value = descriptionTextBox.Text;
           comm.Parameters.Add("@StatusID", System.Data.SqlDbType.Int);
           comm.Parameters["@StatusID"].Value = 1;
      
               conn.Open();
               comm.ExecuteNonQuery();
               Response.Redirect("HelpDesk.aspx");
          
  conn.Close();

and in MS-SQL 2008 i wrote


SQL
CREATE PROCEDURE InsertHelpDesk1
(
@EmployeeID int,
@StationNumber int,
@CategoryID int,
@SubjectID int,
@Description nvarchar(50),
@StatusID int
)
AS
INSERT INTO Dorknozzle1.dbo.HelpDesk1 (EmployeeID, StationNumber, CategoryID,
SubjectID, Description, StatusID)
VALUES (@EmployeeID, @StationNumber, @CategoryID, @SubjectID,
@Description, @StatusID)


Here Helpdesk1 is table name

I am getting error on
C#
comm.ExecuteNonQuery();

and error i got is

Could not find stored procedure 'InsertHelpDesk1'

please tell me what i am missing
Thanx and regards
Posted
Updated 15-Nov-11 23:04pm
v2
Comments
[no name] 16-Nov-11 5:08am    
Have you varified the connection string is pointing to the correct database?

Use
C#
comm = new SqlCommand("dbo.InsertHelpDesk1", conn);


Also check the schema name of procedure . If its not dbo then you need to change it to dbo. Let me know what happens

[edit] I know it is only a one liner, but please format all code blocks - it is a good habit to get into so you don't forget on mulitlined code
 
Share this answer
 
v3
Bring up SQL Server Management Studio, and check that you executed the stored procedure insert code: i.e. that the procedure exists in exactly the database you are referencing via your connection string.

The error message is quite explicit: the procedure is not there. Either you didn't cretae it, or you have created it in a different database.
 
Share this answer
 
Comments
Reiss 16-Nov-11 5:14am    
In SQL 2008 didn't they change it that if the account you are using doesn't have permission to the sproc you now get the can't find error rather than the oiriginal you don't have permission error - or am I am getting mixed up with something else?
I checked ur code.. It insert without any errors
Please check your Database whether the stored procedure is available
Please check your web config file whether u have mention the database name<br />
properly


Regards
Prince Antony
 
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