简体   繁体   English

找不到存储过程

[英]Can't find stored procedure

When I try to update my table's data, I'm getting error 当我尝试更新表的数据时,出现错误

Can't find stored procedure 找不到存储过程

What's wrong? 怎么了?

SQL: SQL:

CREATE PROCEDURE GetContactName
   @Name char(20),
   @SecondName char(20) output
as
   SELECT @SecondName = [Second Name] 
   FROM WPF.dbo.contacts 
   WHERE Name = @Name

C#: C#:

sqlConnection.Open();
SqlCommand cmd = new SqlCommand("GetContactName", sqlConnection);
cmd.CommandType = CommandType.StoredProcedure;

SqlParameter param = new SqlParameter();
param.ParameterName = "@Name";
param.SqlDbType = SqlDbType.Char;
param.Direction = ParameterDirection.Input;
cmd.Parameters.Add(param);

param = new SqlParameter();
param.ParameterName = "@SecondName";
param.SqlDbType = SqlDbType.Char;
param.Size = 20;
param.Direction = ParameterDirection.Output;
cmd.Parameters.Add(param);

cmd.ExecuteNonQuery();
sqlConnection.Close();

Edit1 EDIT1

I'm using VS13 and SQL Server 2008 Management Studio. 我正在使用VS13和SQL Server 2008 Management Studio。

I can't find stored procedure, but when I'm executing the SQL code, it says that the procedure already exists. 我找不到存储过程,但是当我执行SQL代码时,它说该过程已经存在。

Connection string: 连接字符串:

Data Source=HOME;Initial Catalog=WPF;Integrated Security=True
  • Database : WPF 数据库: WPF
  • Schema: dbo.contacts 架构: dbo.contacts

It's a problem of database schema. 这是数据库架构的问题。 Check to see if the default schema for the user id used in your connection string matches your SP's schema. 检查连接字符串中使用的用户ID的默认架构是否与SP的架构匹配。

Just add the USE YourdataBaseName follow by GO above your query. 只需在查询上方添加USE YourdataBaseName,然后添加GO即可。

**USE  YourdataBaseName
Go**

CREATE PROCEDURE GetContactName
   @Name char(20),
   @SecondName char(20) output
as
   SELECT @SecondName = [Second Name] 
   FROM WPF.dbo.contacts 
   WHERE Name = @Name
C#:     

For some reason, when you create a procedure using sql-query , it is not shown in the folder "Stored Procedures". 由于某些原因,当您使用sql-query创建过程时,该过程不会显示在“存储过程”文件夹中。 But if you create a procedure by selecting the appropriate option from the context menu in the "Stored Procedures" folder, it is displayed and everything works. 但是,如果您通过从“存储过程”文件夹的上下文菜单中选择适当的选项来创建过程,则该过程将显示出来,并且一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM