无法找到程序 [英] Procedure could not be found
问题描述
你好,
在开始之前我应该注意,在询问这个问题之前我已经查看了每个谷歌搜索结果
我的数据库中有以下SP:
Hello,
Before starting I should note that I have already looked through every google search result before asking this question
I the following SP in my database:
ALTER procedure [dbo].[chercher_client]
@Code_client nvarchar(50),
@Intitule_client varchar(100)
as
IF (@Code_client is not NULL AND @Code_client!='')
BEGIN
IF (@Intitule_client IS not NULL AND @Intitule_client!='')
select * from Clients where Code_client=@Code_client and Intitule_client=@Intitule_client
ELSE
select * from Clients where Code_client=@Code_client
END
ELSE IF (@Intitule_client is not null AND @Intitule_client!='')
BEGIN
select * from Clients where Intitule_client=@Intitule_client
END
这是我用来执行SP的C#代码
And this is the C# code I am using to execute the SP
<pre> public void Chercher_client(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection(Properties.Settings.Default.Con);
connection.Open();
SqlCommand command = new SqlCommand("chercher_client", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@code_client", chercher_client_code.Text);
command.Parameters.AddWithValue("@Intitule_client", chercher_client_Intitule.Text);
command.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = command;
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
if (dt.Rows.Count < 1)
{
MessageBox.Show("Aucun résultat pour cette recherche");
}
else
{
resultat_client.DataSource = dt;
resultat_client.DataBind();
resultat_client.Visible = true;
}
connection.Close();
}
我的尝试:
我检查了数据库中是否存在SP。
我在SSMS上执行SP并且工作正常。
我尝试执行其他旧程序同一个c#过程中的SAME数据库检查它是否是连接问题,但它们工作正常。
我用一个简单的选择查询做了一个新的测试程序,但它也不起作用。
What I have tried:
I checked that the SP exists in the DB.
I executes the SP on SSMS and it's working fine.
I tried executing other older procedures from the SAME database in the same c# procedure to check if it's a connection problem, but they work fine.
I made a new test procedure with a simple select query and it doesen't work neither.
推荐答案
尝试:
Try:
command.CommandType = CommandType.StoredProcedure;
这听起来像是你连接到SQL的用户,因为没有EXECUTE
对存储过程的权限。
It sounds like the user you're connecting to SQL as doesn't haveEXECUTE
permission on the stored procedure.
- 在SSMS中,右键单击存储过程并选择权限页面。
- 如果您的用户未出现在列表中,请单击搜索。 ..按钮并输入您的用户名。
- 在列表中选择您的用户,然后点击k在有效选项卡上。
- 如果有效权限列表不包含EXECUTE,则您的用户无权执行该sproc。
Grant存储过程的权限 - SQL Server | Microsoft Docs [ ^ ]
这篇关于无法找到程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!