SIGN UP MEMBER LOGIN:    
ARTICLE

What is SMO?

Posted by Amit Choudhary Articles | SQL Server 2012 May 03, 2010
SQL Server Management Objects (SMO) are objects designed for programmatic management of Microsoft SQL Server.
Reader Level:

SQL Server Management Objects (SMO) are objects designed for programmatic management of Microsoft SQL Server.

We can integrate SMO into any .NET based applications.

SMO is also compatible with SQL Server version 7.0, SQL Server 2000, and SQL Server 2005, which makes it easy to manage a multi-version environment.

Following code is used to run the Microsoft SQL Server Query files(script files) kept in applications bin\Debug folder, with SMO.

C# Code:

//Add refrence Microsoft.Sqlserver.Smo .dll;
using Microsoft.SqlServer.Management.Smo;
//Add refrence Microsoft.SqlServer.ConnectionInfo .dll;
using Microsoft.SqlServer.Management.Common;

        string tableText = string.Empty;
        tableText = Server.MapPath(@"~\ScriptFile\")+"TableScripts.sql";
        Server s = new Server();
        ServerConnection svrCon;
        Database objDb=s.Databases["MyDB"];
        svrCon = s.ConnectionContext;
        svrCon.ServerInstance = "serverName";
        svrCon.LoginSecure = false;
        if (svrCon.LoginSecure == false)
        {
            svrCon.Login = "";
            svrCon.Password = "";
        }
      using (Microsoft.VisualBasic.FileIO.TextFieldParser FileReader=new Microsoft.VisualBasic.FileIO.TextFieldParser("")){
          tableText = FileReader.ReadToEnd();
      }
      if (string.IsNullOrEmpty(tableText))
      {
          objDb.ExecuteNonQuery(tableText);
      }
    }

Login to add your contents and source code to this article
share this article :
post comment
 

Hi...


Solution Application 
Application
Referans-->Add Referans-->Browse-->
C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies-->
 in this  ...smo.dll You add
Microsoft.SqlServer.Management.Sdk.Smo
Microsoft.SqlServer.Smo
Microsoft.SqlServer.SqlEnum
Microsoft.SqlServer.ConnectionInfo

Then;
In Application;
using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common;

It can be help you;
http://www.sqldbatips.com/showarticle.asp?ID=34

Posted by nagihan Demirhan Nov 22, 2010

Hi...


Solution Application 
Application
Referans-->Add Referans-->Browse-->
C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies-->
 in this  ...smo.dll You add
Microsoft.SqlServer.Management.Sdk.Smo
Microsoft.SqlServer.Smo
Microsoft.SqlServer.SqlEnum
Microsoft.SqlServer.ConnectionInfo

Then;
In Application;
using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common;

Posted by nagihan Demirhan Nov 22, 2010

hi..

where can I find the Microsoft.Sqlserver.Smo .dll file?

Venkat919

Posted by Venkat T Nov 10, 2010

hi..

where can I find the Microsoft.Sqlserver.Smo .dll file?

Venkat919

Posted by Venkat T Nov 10, 2010

Great!!! This will be of good help to have control over SQL Server.

Niraj
www.GonagpuR.com

Posted by nirajranka May 04, 2010
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor