Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2011
    Posts
    13

    Unanswered: code thinks deleted stored procedure still exists

    Hello,

    I'm writing some code to create stored procedures in a database. In order to test it out, I deleted a stored procedure (right clicking in

    SQL Server 2008 and clicking on delete) and then ran my code to see if it would create it.

    My code looks like this:

    Code:
    SqlCommand command = new SqlCommand();
    SqlConnection conn = database.TypeLibraryDatabaseConnection;
    
    command.Connection = conn;
    
    // create the command to create the stored procedure
    command.CommandText = database.GetProcedure(node.Name);
    
    // create the stored proc in the database
    try
    {
    	command.ExecuteNonQuery();
    }
    catch
    {
    }
    
    command.Dispose();
    database.GetProcedure(node.name) basically gets a string containing the SQL script to create the stored procedure.

    command.ExecuteNonQuery() throws an SqlException that says: "There is already an object named 'SecuritySession_DeleteSessionById' in the

    database." But I deleted it! Why does it think it's still there?

    Thanks for any help.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Since you refer to a SQLException, I'll assume that you're writing VB.NET and not VB or VBA. Knowing the vintage and edition of the compiler would help, as would knowing the ADO versions used for the compile and runtime environments.

    The actual problem could be any of several things, but the contents of command.CommandText is the most likely culpret in my mind.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Aug 2004
    Location
    Dallas, Texas
    Posts
    831
    Might also be that you deleted one copy in a database and there is another copy in different database where your connection object is pointing.

  4. #4
    Join Date
    Nov 2011
    Posts
    13
    Turned out I was creating them in the wrong database. Problem solved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •