Export (0) Print
Expand All

How to: Create a Visual C# SMO Project in Visual Studio .NET

Updated: 5 December 2005

This section describes how to build a simple SMO console application.

This example imports namespaces, which enables the program to reference SMO types. The import of the Agent namespace is optional. The Agent namespace is required only for applications that use SQL Server Agent functionality. The Common namespace is required to establish a secure connection to the instance of SQL Server. The SqlClient namespace is used to debug SQL exception errors.

  1. Start Visual Studio 2005.

  2. On the File menu, click New Project. The New Project dialog box appears.

  3. In Project Types dialog box, select Visual C# Projects. In the Templates pane, select Windows Application.

  4. (Optional) In Name, type the name of the new application

  5. Select the Visual C# application type. For the examples that follow select Console Application.

  6. On the Project menu, select Add Reference. The Add Reference dialog box appears.

  7. Select Browse, locate the SMO assemblies in the C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies folder, and select the following files:

    Microsoft.SqlServer.ConnectionInfo.dll

    Microsoft.SqlServer.Smo.dll

    Microsoft.SqlServer.SmoEnum.dll

    Microsoft.SqlServer.SqlEnum.dll

    ms162129.note(en-US,SQL.90).gifNote:
    Use the Ctrl key to select more than one file.

  8. Add the additional SMO assemblies if you are specifically programming Service Broker or WMI:

    Microsoft.SqlServer.ServiceBrokerEmum.dll

    Microsoft.SqlServer.WmiEmum.dll

  9. Click Open.

  10. On the View menu, click Code.-Or-Select the Program1.cs [Design] Windows and double click the windows form to display the code window.

  11. In the code, before the namespace statement, type the following using statements to qualify the types in the SMO namespace:

    using Microsoft.SqlServer.Management.Smo;
    using Microsoft.SqlServer.Management.Common;
    
  12. SMO has various namespaces under Microsoft.SqlServer.Management.Smo, such as Microsoft.SqlServer.Management.Smo.Agent. Add these namespaces as needed.

  13. You can now add your SMO code.

Community Additions

ADD
Show:
© 2015 Microsoft