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.

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved