| title | Create a Visual Basic SMO Project in Visual Studio .NET | Microsoft Docs | |
|---|---|---|
| ms.custom | ||
| ms.date | 06/13/2017 | |
| ms.prod | sql-server-2014 | |
| ms.reviewer | ||
| ms.technology | database-engine | |
| ms.topic | reference | |
| dev_langs |
|
|
| helpviewer_keywords |
|
|
| ms.assetid | d7a3892c-0f1c-4c4d-8480-b58dce3720bc | |
| author | mashamsft | |
| ms.author | mathoma | |
| manager | craigg |
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 [!INCLUDEssNoVersion] Agent. The Common namespace is required to establish a secure connection to the instance of [!INCLUDEssNoVersion]. The SqlClient namespace is used to process SQL exception errors.
-
Start [!INCLUDEvsOrcas] (or [!INCLUDEvsprvslong]).
-
On the File menu, click NewProject. The New Project dialog box appears.
-
In Project Types dialog box, select Visual Basic, and then select Windows. In the [!INCLUDEvsprvs] Installed Templates pane, select Console Application.
-
(Optional) In the Name field, type the name of the new application.
-
Click OK to load the [!INCLUDEvbprvb] console application template.
-
On the Project menu, select Add Reference. The Add Reference dialog box appears.
-
Click Browse, locate the SMO assemblies in the C:\Program Files\Microsoft SQL Server\120\SDK\Assemblies folder, and then select the following files. These are the minimum files that are required to build an SMO application:
Microsoft.SqlServer.ConnectionInfo.dll
Microsoft.SqlServer.SqlEnum.dll
Microsoft.SqlServer.Smo.dll
Microsoft.SqlServer.Management.Sdk.Sfc
[!NOTE]
Use theCtrlkey to select more than one file. -
Add any additional SMO assemblies that are required. For example, if you are specifically programming [!INCLUDEssSB], add the following assemblies:
Microsoft.SqlServer.ServiceBrokerEmum.dll
-
Click Open.
-
On the View menu, click Code.-Or-Select the Module1.vb window to show the code window.
-
In the code, before any declarations, type the following Imports statements to qualify the types in the SMO namespace.
Imports Microsoft.SqlServer.Management.Smo Imports 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.