views:

406

answers:

10

So, not sure what is happening. But I have stored procedure and it keeps disappearing out of my DB in SQL 2k.

I can add it again and then try to execute it from my web app and i get an exception saying the stored procedure cant be found. So then ill go back to management and refresh and its gone again !?!

here is the config for the stored proc:

set ANSI_NULLS OFF
set QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[USP_Equipment_Delete]
    @EquipmentID int
AS

DELETE FROM [dbo].[Equipment]
WHERE
    [EquipmentID] = @EquipmentID

None of my other stored procedure disappear. This is the only one. I have easily 100 in there. They all use the same SQLHelper class. This one just keeps disappearing!!!??!!

Any help or suggestions are appreciated!

Thanks so much!

+1  A: 

Do you have a CREATE PROCEDURE anywhere? You can't ALTER a procedure if it doesn't exist.

great_llama
Yes, I created it with the following...CREATE PROCEDURE [dbo].USP_Equipment_Delete @EquipmentID intASDELETE FROM [dbo].[Equipment]WHERE [EquipmentID] = @EquipmentIDGOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS OFF GO
gmcalab
Another thought... do you have anything in your database scripts that drops a procedure before you create it? And if so, is that piece of code on one of your other stored procedures dropping this procedure instead?
great_llama
+1  A: 

Perhaps the code to access the stored procedure is using a different context other than dbo. Make sure to add dbo.USP_Equipment_Delete to the code using it.

Gustavo Cavalcanti
+2  A: 

Are you "using" the correct database?

Try using database name above where you're executing your stored procedure, just to make sure.

hypoxide
+1  A: 

So what does this return?

sp_help USP_Equipment_Delete
Garrett
USP_Equipment_Delete,dbo,stored procedure,2009-05-13 10:49:25.310@EquipmentID,int,4,10,0,1,NULL
gmcalab
The fact that it returned something means that the sproc *does* exist. Maybe the issue is how it's being called? Just guessing. =)
Garrett
A: 

Check if the "Initial Catalog" in your connection string is set to the correct database.

Put the database in single user mode (and make sure you're the single user) and check if the procedure still disappears every hour?

Andomar
The initial string is correct. The database is the correct one. When I go into Enterprise Manager and browse the stored procedures its missing. I then add it again. In no less than an hour, I refresh and its gone again.
gmcalab
Did you make an snide remark about the system administrator's wife recently? :)
Andomar
hahaahahahahahaha classic
gmcalab
A: 

Perhaps there's a job thats restoring an old backup periodically?

Vixen
ill double check that, i dont think that is happening because it would also kill my other additions. let me verify that tho
gmcalab
There are NO jobs running to restore...
gmcalab
+17  A: 

You were creating this or another stored proc and at the end of your code, maybe after a comment, where you did not see it you have a drop of this proc.

Take a look at your db using:

select syo.name
from syscomments syc
    join sysobjects syo on
        syo.id = syc.id
where syc.[text] like '%DROP PROC%'
Peter
I'm not sure what you mean by this...
gmcalab
I fixed the select. Run it and see. What happens is that you create proc 'b', but in your query window at the bottom you have a drop of this proc. That drop happens every time proc 'b' is run.
Peter
+1 The query basically searches for a stored procedure that contains a DROP statement. Great idea, run it!
Andomar
DUDE thank you! that worked!!!! It had a drop procedure in it. you helped me so much. im gonna update that and we will see what happens now. THANKS SO MUCH!
gmcalab
Talk about psychic debugging! I'm gonna save this somewhere. Btw don't forget to vote this answer up in addition to accepting it!
Andomar
I already set it as my accepted answer. And it also wont let me vote it up :( i have less than a 15 rep...
gmcalab
I can give you 10 rep by upvoting the question... but that leaves you 2 rep short. Rofl!
Andomar
haha thanks much that most appreciated especially the help to the problem once again BRAVO
gmcalab
NP. Glad it fixed the problem.
Peter
Great fix. At first I wasn't sure what was up either. It tells you what PROC has the drop statement. In my case the prior PROC did not have a closing "GO" and therefore was running into my IF EXISTS and dropping the next PROC.
rball
A: 

If it's there, then this query must return a record:

SELECT * FROM sysobjects 
WHERE id = OBJECT_ID('USP_Equipment_Delete') 
      AND OBJECTPROPERTY(id, N'IsProcedure') = 1
eKek0
-1 This searches for objects named 'USP_Equipment_delete'; what good will that do?
Andomar
it searches for IDs, not for names: an object with an ID equals to the ID of the stored procedure USP_Equiment_Delete
eKek0
do you read id = OBJECT_ID('USP_Equipment_Delete')?
eKek0
Yeah, I think I understand. Did you know object_id('spname') returns null if the stored procedure doesn't exist? The -1 is because I can't see the relation to the question.
Andomar
A: 

Did you fix it? I am having the same problem with SQL 2008

CREATE PROCEDURE insertarVisita @email varchar(50), @IP ntext, @url ntext, @timeStarted char(25) AS INSERT INTO registroDeVisitas (email, IP, ID, url, timeStarted) VALUES
( @email,@IP, NEWID(),@url, @timeStarted) GO

+3  A: 

I had the same problem and I just fixed it:

In the script file it was missing the "GO" statement between the end of the stored procedure and the beginning of the next "IF EXIST THEN DROP" statement.

So what happened was that the drop statement was getting appended to the end of whatever stored procedure was above it in the script. So when the software ran the stored procedure it would drop whatever stored procedure was below it in the script.

It seems so obvious to us now but didn't make any sense at the time. We found it running the SQL profiler against a customer's database that was having the problem in the field.

Same with me.................
rball