I am maintaining a classic ASP website that has a SQL Server 2005 backend. For a small piece of new functionality I wrote a stored procedure to do an insert. This is the o
If the error message only occurs locally, try opening the sql file and press the play button.
Could not find stored procedure?---- means when you get this.. our code like this
String sp="{call GetUnitReferenceMap}";
stmt=conn.prepareCall(sp);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
currencyMap.put(rs.getString(1).trim(), rs.getString(2).trim());
I have 4 DBs(sample1, sample2, sample3) But stmt
will search location is master
Default DB then we will get Exception.
we should provide DB name then problem resolves::
String sp="{call sample1..GetUnitReferenceMap}";
You may need to check who the actual owner of the stored procedure is. If it is a specific different user then that could be why you can't access it.
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.
I had:
USE [wrong_place]
GO
before
DECLARE..
Sometimes this can also happen when you have a stored procedure being called with parameters. For example, if you type something like:
set @runProc = 'dbo.StoredProcedure'
exec @runProc
This will work, However:
set @runProc = 'dbo.StoredProcedure ''foods'''
exec @runProc
This will throw the error "could not find stored procedure dbo.StoredProcedure 'foods'", however this can easily be overcome with parantheses like so:
set @runProc = 'exec dbo.StoredProcedure ''foods'''
exec (@runProc)