Checking if an object exists

  • Is there a way using SMO to find out if an object exists?

    I want to find out if this sp exists on the server

    [dbo].[spGetActiveEmps]

    I know I would have to use something like:

    theserver.Databases.Item(DBName).StoredProcedures.Item([dbo].[spGetActiveEmps])

     

  • So what do you find wrong with that technic (didn't try it, but seems to do the job).

     

    What are you trying to do exacty in that process?  Maybe there's another approach altogether.

  • Basicly we have this folder that has all of these sql server scripts (mostly Stored Procs)

    So what I have to do is loop through the directory, get the file name and then see if an object with that same name and type exists in the database.  if not I'm going to output the filename to a file so we know which scripts are missing in the DB

  • I'd simply run something like this on the server once :

    SELECT O.NAME FROM YourDbNameHere.dbo.SysObjects O WHERE OBJECTPROPERTY(O.id, 'IsMsShipped') = 0 ORDER BY O.NAME

     

    Then do myrs.Filter to find a match.  No need to ping the server on each file to get this info.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply