MS SQL Server
  Home arrow MS SQL Server arrow Page 4 - 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 
Mobile Linux 
App Generation ROI 
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 - Understanding the SMO connectivity


    (Page 4 of 5 )

    Let us go through some of the important statements within the above code snippet.  The first statement from the code is the following:

     

    Imports Microsoft.SqlServer.Management.Smo

    We need the above statement to “import” all classes and other declarations to work with our form.  In fact, we need to consider that the “Microsoft.SqlServer.Management.Smo” namespace is the heart of SMO. 

     

    Dim svr As Server = New Server()

    The above statement creates a new object “svr” based on the class “Microsoft.SqlServerManagement.Smo.Server”.  When the object (“svr”) gets created, it automatically tries to connect to the default instance of SQL Server on the OS where our SMO application is running.  It tries to connect with “Windows Authentication” by default (also called “Secured Connectivity”).

    If you wanted to connect to another instance, you can modify the above statement as follows:

     

    Dim svr As Server = New Server(“192.168.1.2\SQL2K5”)

    The above statement tries to connect to the instance named “SQL2K5” existing at “192.168.1.2” (still based on “Windows Authentication”).

    If you would like to connect by providing SQL Server authentication, you may need to modify your code as shown here:

          Dim svr As Server = New Server(“192.168.1.2\SQL2K5”)
          svr.ConnectionContext.LoginSecure = false

          svr.ConnectionContext.Login = "username"
          svr.ConnectionContext.Password = "password"
     
    Once you connect to a SQL Server instance, you can retrieve information of that instance with the following properties existing in “Microsoft.SqlServer.Management.Smo.Server” class.
    • Name
    • InstanceName
    • Information.Product
    • Information.VersionString
    • Information.Edition
    • Information.Language

    Since the above properties are self-explanatory, I shall leave them without any explanation.  I don’t want to stop here.  We shall further extend our solution to get more important information from the same database instance.  Let us proceed to the next section.

    More MS SQL Server Articles
    More By Jagadish Chaterjee


       · 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 3 hosted by Hostway
    Stay green...Green IT