Use C # to determine whether the database server has been started

          When many projects are started need to connect to the database, it is determined whether to start the database server will be very necessary, how to determine whether the database server to start it?

Can be judged by judging whether the database service starts, of course, I looked online and it was also said by the registry can be judged, here I will talk about my ways:

/// <the Summary>
        /// database to determine whether the service has started, if you have started to return True, otherwise return False
        /// </ the Summary>
        /// <returns A> </ returns A>
        Private BOOL JudgeDBServerStatus ()
        {
            BOOL = to false ExistFlag;
            the ServiceController [] = ServiceController.GetServices-Service ();
            for (int I = 0; I <service.Length; I ++)
            {

                // Since we installed the database system when the server, usually named xxx, we will default database service name is MSSQL $ xxx, and

                // this is certainly not entirely, the environment vary depending oh, you may also be used to determine a service display name such as: service [i] .DisplayName

                IF (-Service [I] .ServiceName.ToString () the Contains ( "MSSQL $").)
                {
                    ExistFlag = to true;
                    String strOuput = string.Format ( "service name database server starts: {0}, a service display name: { }. 1 \ n-",-Service [I] .ServiceName,-Service [I] .DisplayName);
                    // write information output to the log file
                    DllComm.TP_WriteAppLogFileEx (DllComm.g_AppLogFileName, strOuput);
                }
            }
            return ExistFlag;
        }


The above method if there is not the right place I hope you point out. Thank you, oh.


Reproduced in: https: //www.cnblogs.com/kevinGao/archive/2012/05/07/2524543.html

Guess you like

Origin blog.csdn.net/weixin_33721427/article/details/93053216