开发者

.net CLR project says "Could not find stored procedure"

开发者 https://www.devze.com 2023-04-03 02:26 出处:网络
I\'am very new to .net and all Microsoft developer technologies. I\'am working on a CLR project. I just want to store a string and it\'s hash in the database (MS SQL Server). I created a stored proced

I'am very new to .net and all Microsoft developer technologies. I'am working on a CLR project. I just want to store a string and it's hash in the database (MS SQL Server). I created a stored procedure in VS 2010. When I run the test SQL script, it says "Could not find Stored Procedure". Code is as follows: Stored Procedure

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;


public partial class StoredProcedures
 {
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void CDA_hashSProc()
    {
        using (SqlConnection connection = new SqlConnection("context connection=true"))
        {
            connection.Open();
   开发者_开发百科         SqlCommand cmd = new SqlCommand("CDA_HashTest", connection);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@data", SqlDbType.VarChar, 4000);
            cmd.Parameters["@data"].Value = "Hello";
            cmd.Parameters.Add("@hashdata", SqlDbType.VarChar, 4000);
            Security.Hash hash = new Security.Hash();
            cmd.Parameters["@hashdata"].Value = (SqlString)hash.shaHash("Hello World");
            SqlDataReader dr = cmd.ExecuteReader();
            dr.Close();
       }
    }

};

USE [NWebED]
GO
/****** Object:  StoredProcedure [dbo].[CDA_HashTest]    Script Date: 09/07/2011 11:36:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[CDA_HashTest] 
    -- Add the parameters for the stored procedure here
    @data varchar(max),
    @hashdata varchar(max)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    -- Insert statements for procedure here
    insert into CDA_Encryption_Test (CDA_Document, CDA_Hash) values (@data, @hashdata)  
END

ERROR: Could not find stored procedure 'dbo.CDA_hashSProc'.

Please help.

Thanks a lot

Varun


Typically this error is caused by a typo in the stored procedure name. The error: Could not find stored procedure 'dbo.CDA_hashSProc'. I would suspect you have actually wrtten this your line underneath where you open your connection as:

 SqlCommand cmd = new SqlCommand("CDA_hashSProc", connection); 


you need to register the assembly in SQL for it to become available there

look here http://msdn.microsoft.com/en-us/library/ms190790.aspx

and specifically here http://msdn.microsoft.com/en-us/library/ms189524.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号