Search code examples
javat-sqlstored-proceduressql-server-2000junit4

Delete Stored Procedure through remote


I am creating and testing a stored procedure through remote using JUnit , my user name is test and this is my code,

String sql = "create procedure test.firstProc3 AS select GETDATE()";
cursor.execute(sql);
cursor.executeQuery("firstProc3");

ANd to drop the procedure:

String dropSQL = "DROP PROCEDURE test.firstProc3";
cursor.execute(dropSQL);

Since the Drop Procedure is not working, I am unable to run the same SP for the second time ( new session) My error is:

There is already an object named 'firstProc3' in the database.

When I gave sp_help on the server side, the table had the row with the value

firstProc3 test stored procedure

However when I give DROP PROCEDURE test.firstProc3 in the Query analyzer, the row is getting deleted from the table.

What could be the issue in trying to do the same operation through Junit?

Are there any permissions to be set?

PS - the user test has the db_ddladmin enabled.


Solution

  • I managed to finally solve the problem by using the following :

    declare @object_id int
    select @object_id = object_id('test.firstProc5')
    EXEC sp_MSdrop_object @object_id
    GO
    

    This is removing the data from the table too.And I am able to successfully run the Testcase multiple times !

    Thanks for your help :)

    The link I referred to is here, hope it helps someone:

    http://www.mssqlcity.com/Articles/Undoc/SQL2000UndocSP.htm