gpt4 book ai didi

"could not find stored procedure"(“找不到存储过程”)

转载 作者:bug小助手 更新时间:2023-10-25 21:35:44 34 4
gpt4 key购买 nike



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 only user stored procedure in the database.

我正在维护一个经典的ASP网站,有一个SQL Server2005后端。对于一小部分新功能,我编写了一个存储过程来执行插入。这是数据库中唯一的用户存储过程。



When I attempt to call the stored procedure from code I get the following error:

当我尝试从代码中调用存储过程时,我得到以下错误:




Microsoft OLE DB Provider for SQL Server error '80040e14'
Could not find stored procedure 'InsertGroup'.
/newGroup.asp, line 84


The DB uses SQL Server authentication. When I connect to the DB server in Visual Studio using the same user/pw as in the connection string the stored procedure is not visible but all tables are.

数据库使用SQL Server身份验证。当我在Visual Studio中使用与连接字符串中相同的用户/pw连接到DB服务器时,存储过程不可见,但所有表都可见。



The user has datareader and datawriter roles and explicit execute permission on the stored procedure.

该用户具有DataReader和DataWriter角色,并对存储过程具有显式执行权限。



What am I missing?

我遗漏了什么?



UPDATE: My apologies, the server admin misinformed me that it was a 2000 server when it is actually a 2005 server (running on Windows Server 2003 x64).

更新:对不起,服务器管理员误导我说它是2000服务器,而实际上它是2005服务器(运行在Windows Server2003x64上)。


更多回答
优秀答案推荐

Walk of shame:

羞耻之行:



The connection string was pointing at the live database. The error message was completely accurate - the stored procedure was only present in the dev DB. Thanks to all who provided excellent answers, and my apologies for wasting your time.

连接字符串指向实时数据库。错误消息完全准确--存储过程只存在于开发数据库中。感谢所有提供出色答案的人,并对浪费您的时间表示歉意。



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.

您可能需要检查存储过程的实际所有者是谁。如果它是一个特定的不同用户,那么这可能是您无法访问它的原因。



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:

这将抛出错误“找不到存储过程dbo.StoredProcedure‘Foods’”,但是这可以很容易地用下面这样的段落来克服:



set @runProc = 'exec dbo.StoredProcedure ''foods'''
exec (@runProc)


make sure that your schema name is in the connection string?

确保您的架构名称在连接字符串中?



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:

1-存储过程名称在代码中声明存储过程时,请确保不使用EXEC或EXECUTE关键字,例如:



C#

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);

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.

CommandType.StoreProcedure将只查找存储过程名称,而ExecuteNonQuery将在后台执行存储过程。



2- connection string:

2-连接字符串:



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..

宣布..。



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.

我有4个数据库(sample1,sample2,sample3),但stmt将搜索位置为主默认数据库,然后我们将得到异常。



we should provide DB name then problem resolves::

我们应该提供数据库名称,然后问题解决::



String sp="{call sample1..GetUnitReferenceMap}";


One more possibility to check. Listing here because it just happened to me and wasn't mentioned;-)

还有一种可能性需要检查。在此列出是因为这件事发生在我身上,没有人提到;-)



I had accidentally added a space character on the end of the name.
Many hours of trying things before I finally noticed it. It's always something simple after you figure it out.

我不小心在名字的末尾加了一个空格。我尝试了很多小时才终于注意到这一点。在你弄清楚之后,事情总是简单的。



I had the same problem. Eventually I found why. I used a code from web to test output of my procedure. At the end it had a call to Drop(procedure) so I deleted it myself.

我也有同样的问题。最终我找到了原因。我使用Web上的一段代码来测试程序的输出。最后,它有一个删除(程序)的调用,所以我自己删除了它。



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

如果错误消息仅在本地出现,请尝试打开SQL文件并按播放按钮。



My answer according to the problem and what is causing it for me
when i called stored procedure just there is a space before the stored procedure name.
Sometimes it just takes checking the simplest needs

根据问题以及是什么原因,我的答案是,当我调用存储过程时,存储过程名称前有一个空格。有时只需要检查最简单的需求


 datatabel = dataAccessLayer.ReadDataFromDB(" Get_All_Customers",null);

when i deleted the space before Get_All_Customers it's work finely

当我删除Get_All_Customers之前的空间时,它工作得很好



Assuming you are using C# and ADO.NET, It can happen if you don't set SqlCommand.CommandType to CommandType.Text.

假设您使用的是C#和ADO.NET,如果不将SqlCommand.CommandType设置为CommandType.Text,就可能发生这种情况。


更多回答

You should probably mark this as the answer, to help others who may not read to the bottom. It's great that you posted this. I'm sure others have done and will do similar things, and an example of an oversight like this will probably help somebody else find his error.

你或许应该把这句话当做答案,以帮助其他可能读不懂的人。很高兴你发了这个帖子。我相信其他人已经做了,也将会做类似的事情,像这样的疏忽的例子可能会帮助其他人找到他的错误。

@Chloraphil: It's always funny to see that developers tend to think that the most probable explanation is not worth consideration, exploring everything else beforehand. :) +1 for providing the cause of the problem.

@Clloraphil:看到开发人员倾向于认为最可能的解释不值得考虑,事先探索其他一切,这总是很有趣。:)+1,用于提供问题的原因。

I was Googling for a solution to that error and found this question, and it turns out I did the same thing, haha. 6 years later, you're still helping people ;) Thanks!

我在谷歌上搜索这个错误的解决方案,发现了这个问题,结果我也做了同样的事情,哈哈。6年后,你仍然在帮助别人;)谢谢!

Because we use periods in the sproc name, forgetting the brackets causes it. [Employee.GetHistory], not Employee.GetHistory.

因为我们在存储过程名称中使用句点,所以忘记了括号会导致出现这种情况。[Employee.GetHistory],不是Employee.GetHistory。

I had this issue too, Turns out I was also pointing at the wrong DB. In my defence though SqlProfiler was showing the Sproc call next to RPC:completed, so i just assumed it was working.

我也有这个问题,结果我也指出了错误的数据库。在我的辩护中,尽管SqlProfiler在RPC:Complete旁边显示了Sproc调用,所以我只是假设它正在工作。

This has happened to me several times and is quite annoying. Open the DB in SQL Server Management Studio if you can and look for 'dbo' or 'youruser' before the stored procedure. If it doesn't have 'dbo.', drop the existing procedure and recreate it with that as a prefix for the procedure name.

这在我身上已经发生过几次了,非常令人恼火。如果可以,请在SQL Server Management Studio中打开数据库,并在存储过程之前查找‘dbo’或‘you user’。如果它没有‘dbo.’,则删除现有过程并重新创建它,并将其作为过程名称的前缀。

Or, just mention the "owner" (="schema") the stored procedure belongs to as part of the call -- EXEC [dbo].[InsertGroup]

或者,只需在调用中提到存储过程所属的“所有者”(=“架构”)--exec[dbo]。[InsertGroup]

calling it as dbo.InsertGroup or just InsertGroup fails

将其调用为dbo.InsertGroup或仅调用InsertGroup失败

Fails in what way? If it is an access denied error, GRANTing the user you are accessing the database with EXECUTE to dbo.InsertGroup would fix it.

在什么方面失败了?如果这是一个拒绝访问的错误,授予您正在访问数据库的用户EXECUTE TO dbo.InsertGroup可以修复它。

@Michael Haren - bro you just save my sleepless night!!! I am using Godaddy's Plesk Windows Hosting Account - and the way it generates it - is somehow inserts some username crap in the front of the stored procedure - instead of dbo, even though when I ran query I had it like dbo.StoredProcedureName. I had to drop and create it like you said - and now it works like a charm!

@Michael Haren-Broo你拯救了我的不眠之夜!我使用的是GoPardy的Plesk Windows主机帐户--以及它的生成方式--是在存储过程的前面插入一些用户名垃圾,而不是dbo,即使当我运行查询时,它像dbo.StoredProcedureName一样。我不得不像你说的那样放弃并创造它--现在它像一个护身符一样起作用了!

can you be more specific? I'm not familiar with how to do that. Regardless, the database is only using the "dbo" schema.

你能说得更具体些吗?我不熟悉如何做那件事。无论如何,数据库只使用“dbo”模式。

You may have two databases, and you think you are pointing to one database, but in actuality, you are pointing to another. Thus the StoredProc is on one database, but not the one you are running against. This can be a config error.

您可能有两个数据库,并且您认为您指向的是一个数据库,但实际上,您指向的是另一个数据库。因此,StoredProc位于一个数据库上,而不是您正在运行的数据库。这可能是配置错误。

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com