“could not find stored procedure”

后端 未结 10 1140
死守一世寂寞
死守一世寂寞 2020-12-20 11:43

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

相关标签:
10条回答
  • 2020-12-20 11:58

    If the error message only occurs locally, try opening the sql file and press the play button.

    0 讨论(0)
  • 2020-12-20 12:04

    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}";
    
    0 讨论(0)
  • 2020-12-20 12:05

    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.

    0 讨论(0)
  • 2020-12-20 12:10

    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.

    0 讨论(0)
  • 2020-12-20 12:13

    I had:

    USE [wrong_place]

    GO

    before

    DECLARE..

    0 讨论(0)
  • 2020-12-20 12:15

    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)
    
    0 讨论(0)
提交回复
热议问题