Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

How to: Use an SMO Method with a Parameter in Visual Basic .NET

SQL Server 2005

This section describes how to call a method that requires a parameter.

The Table object has a method called RebuildIndexes. This method requires a numeric parameter that specifies the FillFactor.

  1. Start Visual Studio 2005.

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

  3. In the Project Types pane, select Visual Basic. In the Templates pane, select Console Application.

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

  5. Click OK to load the Visual Basic console application template.

  6. On the Project menu, select Add Reference item. The Add Reference dialog box appears. Select Browse and 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.SqlEnum.dll

    Microsoft.SqlServer.SmoEnum.dll

  7. On the View menu, click Code.-Or-Select the Module1.vb window to display the code window.

  8. 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
    
  9. Insert the code below into the main program.

  10. Run and build the application.

Dim srv As Server
srv = New Server
Dim tb As Table
tb = srv.Databases("AdventureWorks").Tables("Employee", "HumanResources")
tb.RebuildIndexes(70)
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.