Skip to content
Advertisement

“Could not find stored procedure” error when called from C# application

I created a stored procedure in SQL Server and tried calling it from my C# application but I am getting a message

Could not find stored procedure

I have already tried all possible solutions from “could not find stored procedure”

Here is the definition of my stored procedure (created successfully)

CREATE PROCEDURE [dbo].TagSaveToDblogic 
    @epcid NVARCHAR(100),
    @antid INTEGER,
    @starttime DATETIME,
    @endtime DATETIME,
    @sigstr INTEGER,
    @locid INTEGER,
    @valid INTEGER
AS
BEGIN
    DECLARE @LAST_LOCID int

    SELECT @LAST_LOCID = [LAST_LOCATION]
    FROM [DocumentTracking].[dbo].[KAWS_CARIBONI_DT_TAGS] 
    WHERE TAG_ID = @epcid

    IF (@LAST_LOCID != @locid)
    BEGIN
        INSERT INTO [DocumentTracking].[dbo].[KAWS_CARIBONI_DT_TEER] (EPC_DOCUMENT_CODE, ANTENNA_ID, READ_START_TIMESTAMP, READ_END_TIMESTAMP, SIGNAL_STRENGTH, LOCATION_ID, VALID_ENTRY) 
        VALUES (@epcid, @antid, @starttime, @endtime, @sigstr, @locid, @valid)
    END
END

Here is a screenshot of the SELECT from sysobjects table where type = ‘P’ and category = 0 https://ibb.co/x2vFQzw

This is my complete code to call the stored procedure from the C# application:

string connetionString = null;
connetionString = "Data Source=192.9.100.250;Initial Catalog=DocumentTracking;User ID=alstom;Password=";

System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connetionString);
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("dbo.TagSaveToDblogic", connection);

command.CommandType = CommandType.StoredProcedure;

command.Parameters.AddWithValue("@epcid", row[2].ToString());
command.Parameters.AddWithValue("@antid", m_curInventoryBuffer.nCurrentAnt);
command.Parameters.AddWithValue("@starttime", m_curInventoryBuffer.dtStartInventory);
command.Parameters.AddWithValue("@endtime", m_curInventoryBuffer.dtEndInventory);
command.Parameters.AddWithValue("@sigstr", (Convert.ToInt32(row[4]) - 129));
command.Parameters.AddWithValue("@locid", 1);
command.Parameters.AddWithValue("@valid", 1);

connection.Open();
int result = command.ExecuteNonQuery();

The last line of the code is where I get the error.

Please help me resolve this error!

Advertisement

Answer

As pointed out by @DimitryTsoy and @JeroenMostert

Adding the following statements did the trick:

USE DocumentTracking
GO

DocumentTracking is the database name.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement