MS SQL Server
  Home arrow MS SQL Server arrow Page 5 - Retrieving SQL Server 2005 Database Info U...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

Retrieving SQL Server 2005 Database Info Using SMO: Basics
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 8
    2006-01-31

    Table of Contents:
  • Retrieving SQL Server 2005 Database Info Using SMO: Basics
  • Creating the Visual Studio 2005 solution to connect to SMO
  • Connecting to the SQL Server database using SMO
  • Understanding the SMO connectivity
  • How do we retrieve “Database” Information about a particular SQL Server instance using SMO?

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Retrieving SQL Server 2005 Database Info Using SMO: Basics - How do we retrieve “Database” Information about a particular SQL Server instance using SMO?


    (Page 5 of 5 )

    The previous code just introduced you to connecting to an instance using SMO.  The information that we retrieved in the previous code is not of much practical use.  Let us further extend the same solution with one more “windows form” which retrieves all “database” related information present in a particular SQL Server database instance.

    Don’t forget to add a new form (such as “form2”) to your existing solution and modify your project properties so that it will be the “start up form” during execution.  The layout of the form will be very similar to that of the one I designed in the previous section.

    Open a code window (by pressing F7) and modify the code in such a way that it looks something this:

    Imports Microsoft.SqlServer.Management.Smo
    Public Class Form2
        Private Sub btnShow_Click(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles btnShow.Click
            Dim svr As Server = New Server(".\sql2k5")
            Dim db As Database
            For Each db In svr.Databases
                Me.TextBox1.Text &= db.Name & ControlChars.NewLine
            Next
        End Sub
    End Class

    The only new part within the above code is this:

            Dim db As Database
            For Each db In svr.Databases
                Me.TextBox1.Text &= db.Name & ControlChars.NewLine
            Next

    “Microsoft.SqlServer.Management.Smo.Databases” is a collection; it contains the list of all databases existing within the connected instance.  You can retrieve each of those using a loop.  For every iteration, the loop fetches a particular “database” into “db.” We extract information about that “database” using its properties and finally add the same to the textbox.

    Summary

    In this article, I touched only the basics of SMO available in Microsoft SQL Server 2005.  You can explore further by referring to SQL Server 2005 books online at Microsoft's website.  You can also develop your own web-based SQL Server database management tool using ASP.NET 2.0 without changing the code at all.  In fact, it all works with .NET. 

    You can extend the possibilities even further to Smart Clients such as Smart Phone, Pocket PC, Tablet PC, and so on. If you are familiar with WMI, you can  extend the possibilities to that level as well.

    For your practice, you can try to develop a simple Backup/Restore utility using SMO together with Visual Basic 2005.  I already contributed an article on that subject, but with SQL-DMO (in SQL Server 2000).  You can check it out at here:  http://www.aspfree.com/c/a/VB.NET/Simple-BackupRestore-Utility-With-SQLDMO-
    Using-VBNET/1/

    My forthcoming articles (related to this subject) will focus on in-depth discussion along with developing some small practical utilities (which may be essential in certain situations).  So, do not forget to check this site frequently :)

    Any comments, suggestions, ideas, improvements, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hi guys, delve into SMO of SQL Server 2005 with this contribution. Have any doubts...
       · You mention that SMO supports Sql Server 7.0. When I tried using it to access my...
       · Hai, it is possible to work with SMO on SQL Server 7.0/2000, if and only if we...
       · Hi your article is pretty good,I use to use dmo and I wonder how to get all the...
     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway