devxlogo

Start SQLServer Dynamically with
VB and SQL-DMO Objects

Start SQLServer Dynamically with
VB and SQL-DMO Objects

Create a new standard exe project and add reference of sqldmo.rll. This file can be found in BinnResources1033sqldmo.rll under SqlServer70 directory.Now add following code and declaration in your form’s code:

 Private WithEvents oSqlServer As SQLDMO.SQLServerPrivate Function StartSqlServer(ByVal strServerName As String, strErrorMsg As String) As BooleanStatic boolFunctionExecuting As Boolean    If Not boolFunctionExecuting Then        BoolFunctionExecuting = True        Set oSqlServer = New SQLServer        With oSqlServer            .Name = strServerName            Do While .Status <> SQLDMOSvc_Running                Select Case .Status                    Case SQLDMOSvc_Paused                        .Continue                    Case SQLDMOSvc_Stopped                        .Start False, strServerName, "sa"                    Case SQLDMOSvc_Starting                        DoEvents                    Case SQLDMOSvc_Unknown                        strErrorMsg = "SqlServer in unknown state"                        Exit Do                End Select            Loop            If .Status = SQLDMOSvc_Running Then                StartSqlServer = True            Else                StartSqlServer = False            End If        End With        Set oSqlServer = Nothing        BoolFunctionExecuting = False    End IfEnd Function

This function works quite well and if you would like to enhance it, use following constants for .Status property :
SQLDMOSvc_Continuing, SQLDMOSvc_Pausing, SQLDMOSvc_Starting, SQLDMOSvc_Stopped, SQLDMOSvc_Stopping.

You can also write code for the events fired by SQLServer object.

See also  Digital Signage Solutions for Agile Software Development Teams
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist