How to get total objects in a Database?

  • Hi all,

    I am using .net 2/C# to write an application that will populate a tree with all the objects available in any given database on a particular Sql 2005 server. I am doing this using SMO. This process seems to be very time consuming. So, I would like to let the user know of the progress using a progress bar. My problem is figuring out the total objects in the selected database in the first place. Since I don't have an idea how, I am unable to properly display the percentage of completion. Can somedoby help me with this? Is there a system stored proc or even an SmoObject property to tell me this number?

    Thanks in advance.

    Babu.

  • That's a good start, but there's some small cleaning to do here :

    SELECT * FROM sys.Objects WHERE OBJECTPROPERTY(object_id, 'IsMsShipped') = 0

  • Depending on what you are doing with your huge list of objects being displayed, you may find that the SMO objects are a lot of unnecessary overhead.

    Look at the Information_Schema views - you can probably fill a treeview in significantly less time without using SMO.

    The MS standard for eye candy seems to have shifted from progress bars to the spinning wheel animated gif. You could take this approach...

  • Babu Mannaravalappil (9/27/2007)


    Hi all,

    I am using .net 2/C# to write an application that will populate a tree with all the objects available in any given database on a particular Sql 2005 server. I am doing this using SMO. This process seems to be very time consuming. So, I would like to let the user know of the progress using a progress bar. My problem is figuring out the total objects in the selected database in the first place. Since I don't have an idea how, I am unable to properly display the percentage of completion. Can somedoby help me with this? Is there a system stored proc or even an SmoObject property to tell me this number?

    Thanks in advance.

    Babu.

    Querying the sys.objects table (and excluding some MS objects) will give you all the schema objects (like tables, views, procs, etc.) Not everything lives in a schema though. If you are interested in all the other objects like XML schema collections, CLR assemblies, routes, users, roles, ... you need to query their relevant system views.

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

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

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