Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Enterprise
Expertise: Beginner
Sep 8, 1999



Application Security Testing: An Integral Part of DevOps

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 \Binn\Resources\1033\sqldmo.rll under SqlServer70 directory. Now add following code and declaration in your form's code:
Private WithEvents oSqlServer As SQLDMO.SQLServer
Private Function StartSqlServer(ByVal strServerName As String, strErrorMsg As String) As Boolean
Static 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
                    Case SQLDMOSvc_Stopped
                        .Start False, strServerName, "sa"
                    Case SQLDMOSvc_Starting
                    Case SQLDMOSvc_Unknown
                        strErrorMsg = "SqlServer in unknown state"
                        Exit Do
                End Select
            If .Status = SQLDMOSvc_Running Then
                StartSqlServer = True
                StartSqlServer = False
            End If
        End With
        Set oSqlServer = Nothing
        BoolFunctionExecuting = False
    End If
End 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.

KulBhushan Sharma
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date