????? ????? ?? ???? ???? SQL Server Express ?? ??? ????? ???? SQL Server Express ???????? Visual Basic ?? Visual C#

?????? ????????? ?????? ?????????
???? ???????: 912426 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

??????

Microsoft SQL Server 2005 Express Edition ???? ????? ??? ????. ?? ???? ????? ??????? Microsoft Visual Studio 2005 ??? SQL Server 2005 Express Edition? ????? ????? ?? ???? ???? SQL Server Express ??? ??? ????? ???????. ????? ??????? ??? ???? ?????? ??????? ?????? ??? ???:
  • ????? ?? ???? ???? SQL Server Express.
  • ??? ????? ???? SQL Server Express ??? ?? ??? ??????? ???? ????.
?????? ?????? ??????? ????????? ? SQL Server 2005 Express Edition ???? ??? SQLEXPRESS. ???? ??? ???? ??? ??? ??? ?????? MSSQL$ SQLEXPRESS.

??????? ????

???????? ??? ???? ?????? ??????? ?? ????? ???? ???? Visual Studio ????? ?? ????? SQL Server Express ????? ???? ??????? ???????:
  1. ??? ????? Visual Studio 2005.
  2. ??? ??? ? ??? ???????? ?? ???? ??? ???????.
  3. ???? ??? Visual Basic ?? ???? C# ??? ????? ????????? ?? ???? ???????? ???? ?????? ??? Visual Studio ?????? ?????.

    ?????? ???? ???????? ??? ????? ????? Module1.vb ?? ????? Visual Basic. ???? ???????? ??? ????? ??? Program.cs ?? ??????? ????? C#.
  4. ????????? ConsoleApplication1 ??? ????? ??????? ?? ??? ????? ??? ?? ???? ????????.
  5. ????? ???? ??? ????? ????? "System.ServiceProcess". ??? ?????? ????? ???? ??????? ???????:
    1. ??? ??????? ???????? ???? ??? ????? ????.
    2. ???? ??? .NET ? ???? ??? System.ServiceProcess? ?? ???? ??? ?????.
  6. ??????? ????????? ???????? ???????? ??? ??? ????????? ????????.

    ?????? ??????? ????????? ???????? ?? ??? Module1.vb ?? ????? Visual Basic. ??????? ????????? ???????? ?? ??????. cs ??? ?? ????? Visual C#.

    Visual Basic
    Imports System
    Imports System.ServiceProcess
    
    Module Module1
    
        Sub Main()
    
            Dim myServiceName As String = "MSSQL$SQLEXPRESS" 'service name of SQL Server Express
            Dim status As String  'service status (For example, Running or Stopped)
            Dim mySC As ServiceController
    
            Console.WriteLine("Service: " & myServiceName)
    
            'display service status: For example, Running, Stopped, or Paused
            mySC = New ServiceController(myServiceName)
            Try
                status = mySC.Status.ToString
            Catch ex As Exception
                Console.WriteLine("Service not found. It is probably not installed. [exception=" & ex.Message & "]")
                Console.ReadLine()
                End
            End Try
            Console.WriteLine("Service status : " & status)
    
            'if service is Stopped or StopPending, you can run it with the following code.
            If mySC.Status.Equals(ServiceControllerStatus.Stopped) Or mySC.Status.Equals(ServiceControllerStatus.StopPending) Then
                Try
                    Console.WriteLine("Starting the service...")
                    mySC.Start()
                    mySC.WaitForStatus(ServiceControllerStatus.Running)
                    Console.WriteLine("The service is now " & mySC.Status.ToString)
    
                Catch ex As Exception
                    Console.WriteLine("Error in starting the service: " & ex.Message)
                End Try
            End If
    
            Console.WriteLine("Press a key to end the application...")
            Console.ReadLine()
            End
        End Sub
    End Module
    Visual C#
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.ServiceProcess;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main()
            {
    
                string myServiceName = "MSSQL$SQLEXPRESS"; //service name of SQL Server Express
                string status; //service status (For example, Running or Stopped)
    
                Console.WriteLine("Service: " + myServiceName);
    
                //display service status: For example, Running, Stopped, or Paused
                ServiceController mySC = new ServiceController(myServiceName);
    
                try
                {
                    status = mySC.Status.ToString();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Service not found. It is probably not installed. [exception=" + ex.Message + "]");
                    Console.ReadLine();
    
                    return;
    
                }
    
                //display service status: For example, Running, Stopped, or Paused
                Console.WriteLine("Service status : " + status);
    
                //if service is Stopped or StopPending, you can run it with the following code.
                if (mySC.Status.Equals(ServiceControllerStatus.Stopped) | mySC.Status.Equals(ServiceControllerStatus.StopPending))
                {
                    try
                    {
                        Console.WriteLine("Starting the service...");
                        mySC.Start();
                        mySC.WaitForStatus(ServiceControllerStatus.Running);
                        Console.WriteLine("The service is now " + mySC.Status.ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error in starting the service: " + ex.Message);
    
                    }
    
                }
    
                Console.WriteLine("Press a key to end the application...");
                Console.ReadLine();
    
                return;
    
            }
    
        }
    }
  7. ???? CTRL + F5 ?????? ????????.

?????

????? ?? ????????? ??? ????? ????? "System.ServiceProcess"? ?? ?????? ???? ???? ????? Microsoft (MSDN) ?????? ??? ?????:
.aspx http://msdn2.microsoft.com/en-us/library/system.serviceprocess (vs.71)
 

???????

???? ???????: 912426 - ????? ??? ??????: 19/???/1434 - ??????: 2.0
????? ???
  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft SQL Server 2005 Express Edition
????? ??????: 
kbprb kbhowto kbmt KB912426 KbMtar
????? ????
???: ??? ????? ??? ??????? ???????? ????? ?????????? ??????? ?????? ??? ??????? ?? ??? ??????? ?? ??????? ??? ??? ?? ???? ????????? ???? ??????? ???????(CTF) ?? ?? ???? ????? ????. ???? ?? ???? ?????????? ??? ???????? ???????? ???? ??? ?? ???????? ??????? ?? ??? ??????? ???????? ?? ??? ??????? ??????? ??? ?????? ?? ?????? ??? ???? ???????? ???????? ?? ????? ??????? ????? ????? ??????. ??? ?? ???????? ???????? ?? ????? ??? ????? ?? ???????? ?? ???? ????? ?? ?????. ?????? ??? ???? ?????????? ???? ?????? ?? ??? ????? ?? ??? ??? ?? ??????? ?? ??? ????? ?? ???? ????? ????? ?? ????? ??????? ???? ?? ???????? ?? ??? ???????.
???? ??? ????? ??????? ?????? ??????????912426

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com