none
check whether sqlserver service started or not, if not then start it. RRS feed

  • Question

  • Hello,

    Is there any way to check whether the sqlserver service started or not?

    If it is not running then how to start it by vb.net

    Thank you guys.


    remember make the reply as answer and vote the reply as helpful if it helps.


    • Edited by Risa- Monday, August 20, 2018 2:48 AM
    Monday, August 20, 2018 2:48 AM

Answers

  • Hi,

    Check if the local Sqlserver is started,if not then start it:

    Private Sub SurroundingSub()
        Dim sc As ServiceController = New ServiceController("MSSQLSERVER")
        If sc.Status = ServiceControllerStatus.Stopped Then
            sc.Start()
            MessageBox.Show("
    The SQL database service started successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End Sub


    Check if remote Sqlserver exists:

    Imports System.Configuration
    Imports System.Net.Sockets

    Private Function TestForServer(ByVal address As String, ByVal port As Integer) As Boolean Dim timeout As Integer = 500 If ConfigurationManager.AppSettings("RemoteTestTimeout") IsNot Nothing Then timeout = Integer.Parse(ConfigurationManager.AppSettings("RemoteTestTimeout")) Dim result = False Try Using socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Dim asyncResult As IAsyncResult = socket.BeginConnect(address, port, Nothing, Nothing) result = asyncResult.AsyncWaitHandle.WaitOne(timeout, True) socket.Close() End Using Return result Catch Return False End Try End Function

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Risa- Monday, August 20, 2018 6:37 AM
    Monday, August 20, 2018 6:36 AM
  • Thanks for your help.

    I got the following way which solved my issue.

    How to detect the status of the SQL Server Express service or start the SQL Server Express service by using Visual Basic or Visual C#


    remember make the reply as answer and vote the reply as helpful if it helps.

    • Marked as answer by Risa- Monday, August 20, 2018 6:20 AM
    Monday, August 20, 2018 6:20 AM

All replies

  • Hello,

    Is there any way to check whether the sqlserver service started or not?

    If it is not running then how to start it by vb.net

    Thank you guys.


    remember make the reply as answer and vote the reply as helpful if it helps.


    If there is a way that I kind of doubt and you shouldn't be doing it anyway by someone showing you or others how to run an attack against MS SQL Server, then ask it in the SQL Server Forums. 

    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home

    Monday, August 20, 2018 4:02 AM
  • Thanks for your help.

    I got the following way which solved my issue.

    How to detect the status of the SQL Server Express service or start the SQL Server Express service by using Visual Basic or Visual C#


    remember make the reply as answer and vote the reply as helpful if it helps.

    • Marked as answer by Risa- Monday, August 20, 2018 6:20 AM
    Monday, August 20, 2018 6:20 AM
  • Hi,

    Check if the local Sqlserver is started,if not then start it:

    Private Sub SurroundingSub()
        Dim sc As ServiceController = New ServiceController("MSSQLSERVER")
        If sc.Status = ServiceControllerStatus.Stopped Then
            sc.Start()
            MessageBox.Show("
    The SQL database service started successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End Sub


    Check if remote Sqlserver exists:

    Imports System.Configuration
    Imports System.Net.Sockets

    Private Function TestForServer(ByVal address As String, ByVal port As Integer) As Boolean Dim timeout As Integer = 500 If ConfigurationManager.AppSettings("RemoteTestTimeout") IsNot Nothing Then timeout = Integer.Parse(ConfigurationManager.AppSettings("RemoteTestTimeout")) Dim result = False Try Using socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Dim asyncResult As IAsyncResult = socket.BeginConnect(address, port, Nothing, Nothing) result = asyncResult.AsyncWaitHandle.WaitOne(timeout, True) socket.Close() End Using Return result Catch Return False End Try End Function

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Risa- Monday, August 20, 2018 6:37 AM
    Monday, August 20, 2018 6:36 AM
  • Thank you Alex!

    remember make the reply as answer and vote the reply as helpful if it helps.

    Monday, August 20, 2018 6:37 AM
  • Thanks for your help.

    I got the following way which solved my issue.

    How to detect the status of the SQL Server Express service or start the SQL Server Express service by using Visual Basic or Visual C#


    remember make the reply as answer and vote the reply as helpful if it helps.

    It's very bad that you have posted this. Now it just opens up someone's eyes on how to create an exploit and run it against MS SQL Server attacking it if they can drop the exploit on the machine.

    It's very bad indeed,  and you have no sense about security on the MS O/S platform.

    https://blog.barkly.com/biggest-data-breaches-2018-so-far

    Monday, August 20, 2018 10:16 AM
  • Thanks for your help.

    I got the following way which solved my issue.

    How to detect the status of the SQL Server Express service or start the SQL Server Express service by using Visual Basic or Visual C#


    remember make the reply as answer and vote the reply as helpful if it helps.

    It's very bad that you have posted this. Now it just opens up someone's eyes on how to create an exploit and run it against MS SQL Server attacking it if they can drop the exploit on the machine.

    It's very bad indeed,  and you have no sense about security on the MS O/S platform.

    https://blog.barkly.com/biggest-data-breaches-2018-so-far

    If it is bad, why MS shared this way with us by that link?

    remember make the reply as answer and vote the reply as helpful if it helps.

    Tuesday, August 21, 2018 7:14 AM
  • Thanks for your help.

    I got the following way which solved my issue.

    How to detect the status of the SQL Server Express service or start the SQL Server Express service by using Visual Basic or Visual C#


    remember make the reply as answer and vote the reply as helpful if it helps.

    It's very bad that you have posted this. Now it just opens up someone's eyes on how to create an exploit and run it against MS SQL Server attacking it if they can drop the exploit on the machine.

    It's very bad indeed,  and you have no sense about security on the MS O/S platform.

    https://blog.barkly.com/biggest-data-breaches-2018-so-far

    If it is bad, why MS shared this way with us by that link?

    remember make the reply as answer and vote the reply as helpful if it helps.

    MS is dumb, and it puts out code that if that code gets into the wrong hands with someone  having  malicious intent it could  wreak havoc.

    You can't see that?

    What if  someone got a clue from the code on how to shutdown a server version of MS SQL Server, becuase MS is dumb enough to present the code that gave them the clue?

    You don't think someone would do it? 

    Hey, little Jimmy didn't have a clue about  it,  little Jimmy may have never found it, but for you posting the possibility right in little Jimmy's face.  

     
    Tuesday, August 21, 2018 10:12 AM