简体   繁体   English

存储过程正确解析但不会执行。 无效的对象名称。 Msg 208

[英]Stored procedure parses correctly but will not execute. Invalid object name. Msg 208

I've scripted up a stored procedure as follows. 我编写了一个存储过程,如下所示。 It will parse without errors, but when I try to execute it, it will fail. 它将解析没有错误,但是当我尝试执行它时,它将失败。 The error message reads: Msg 208, Level 16, State 6, Procedure aspnet_updateUser, Line 23 Invalid object name 'dbo.aspnet_updateUser'. 错误消息显示:消息208,级别16,状态6,过程aspnet_updateUser,行23无效的对象名称'dbo.aspnet_updateUser'。

Here is the stored procedure. 这是存储过程。

    USE [PMRS2]
GO
/****** Object:  StoredProcedure [dbo].[aspnet_updateUser]    Script Date: 05/25/2009 15:29:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[aspnet_updateUser]
    -- Add the parameters for the stored procedure here
    @UserName nvarchar(50),
    @Email nvarchar(50),
    @FName nvarchar(50),
    @LName nvarchar(50),
    @ActiveFlag bit,
    @GroupId int

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here

UPDATE dbo.aspnet_Users 
    SET UserName = @UserName, LoweredUserName = LOWER(@UserName), Email = @Email, FName = @FName, LName = @LName, ActiveFlag = @ActiveFlag, GroupId = @GroupId
    WHERE LoweredUserName = LOWER(@UserName)
END

看起来它可能还不存在,将Alter交换为Create。

To avoid this happening in the furture, do what we do, never use alter proc. 为了避免这种情况发生,做我们做的事情,永远不要使用alter proc。 Instead we check for the existance of the proc and drop it if it exists, then create it with the new code: 相反,我们检查proc的存在并删除它(如果存在),然后使用新代码创建它:

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'myProc')
BEGIN
    DROP  Procedure  myProc
END
GO

CREATE PROCEDURE myProc 
(add the rest of the proc here)

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

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