views:

688

answers:

2

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

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
+4  A: 

Looks like it might not exist yet, swap the Alter to a Create.

Martynnw
I'm an idiot. Thanks for that
Chris
+1 for beating everyone else ;)
gbn
Happens to us all!
Martynnw
Apparently I am an idiot too.
smaclell
A: 

To avoid this happening in the furture, do what we do, never use alter proc. Instead we check for the existance of the proc and drop it if it exists, then create it with the new code:

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