Start MS SQL Server Dynamically

Start MS SQL Server Dynamically

Use this code in your C++ executable to start MS SQL Server dynamically on aWindows NT machine. Link to w95scm.lib, which is provided with the SQL 7.0 CD.

 #include "wn95scm.h" //included with Sql7.0 CDBOOL  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 determineservice state.", dwErr);                         return (FALSE);                    }          }          Sleep(5);          dwServiceState = SQLSCMGetLocalServiceState(szService, &dwErr);     }     if (bControlSuccessful)     {          sprintf(szErrorMsg, "Error %lu returned on attempt to change servicestate.", dwErr);     }     return (bControlSuccessful ? TRUE : FALSE);}
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes