dcsimg
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
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: C++, Enterprise
Expertise: Intermediate
May 25, 1999

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Start MS SQL Server Dynamically

Use this code in your C++ executable to start MS SQL Server dynamically on a Windows NT machine. Link to w95scm.lib, which is provided with the SQL 7.0 CD.
 
#include "wn95scm.h" //included with Sql7.0 CD
BOOL  StartSqlServer(LPSTR szErrorMsg)
{
     LPSTR       szService = "MSSQLServer";
     DWORD       dwServiceState, dwErr;
     BOOL        bControlSuccessful;

     bControlSuccessful = TRUE;    // Query service state.
     dwServiceState = SQLSCMGetLocalServiceState(szService, &dwErr);
     while ((dwServiceState != 0) && (bControlSuccessful == TRUE))
     {
          if (dwServiceState == SERVICE_RUNNING)
               break;
          switch (dwServiceState)
          {
               case SERVICE_PAUSED:     // Paused, so continue.
                    bControlSuccessful =  SQLSCMLocalServiceControl(szService,
SQLSCMCmd_CONTINUE,&dwErr, 0, NULL);
                    break;
               case SERVICE_STOPPED:     // Stopped, start service.
                    bControlSuccessful =  SQLSCMLocalServiceControl(szService,
SQLSCMCmd_START, &dwErr, 0, NULL);
                    break;
               default:// Error if state is 0 otherwise state is changing.
                    if (dwServiceState == 0)
                    {    // Error. Return failure.
                         sprintf(szErrorMsg, "Error %lu on attempt to determine
service state.", dwErr);
                         return (FALSE);
                    }
          }
          Sleep(5);
          dwServiceState = SQLSCMGetLocalServiceState(szService, &dwErr);
     }
     if (bControlSuccessful)
     {
          sprintf(szErrorMsg, "Error %lu returned on attempt to change service
state.", dwErr);
     }
     return (bControlSuccessful ? TRUE : FALSE);
}
KulBhushan Sharma
 
Comment and Contribute

 

 

 

 

 


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

 

 

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