Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
SQL database in Microsoft Fabric
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. Use it when you are writing a program that uses SQL Server Agent. The Common namespace is required to establish a secure connection to the instance of SQL Server. The SqlClient namespace is used to process SQL exception errors.
Start Visual Studio
On the File menu, click New and then Project. The New Project dialog box appears.
In the Visual Studio Installed pane, navigate to Templates\Visual C#\Windows and select Console Application.
(Optional) In the Name text box, type the name of the new application.
Click OK to load the console application template.
Follow the instructions on Installing SMO to install the package for your project to reference.
On the View menu, click Code.
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;
SMO has various namespaces under Microsoft.SqlServer.Management.Smo, such as Microsoft.SqlServer.Management.Smo.Agent. Add these namespaces as they are required.
You can now add your SMO code.
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register today