sql server命令行可以让我们使用sql数据库更加的方便,下面就教您教您如何启动及关闭sql server命令行方式,在下面的sql server命令行方式启动脚本中,sql server 安装的是默认名字。
- BOOL StartMsSqlServer()
- {
- PROCESS_INFORMATION pi = {0};
- STARTUPINFO si = {0};
- BOOL bSuccess = FALSE;
- bSuccess = CreateProcess(
- NULL,
- "scm -Silent 1 -Action 1 -Service mssqlserver",
- NULL,
- NULL,
- FALSE,
- CREATE_NO_WINDOW,
- NULL,
- NULL,
- &si, //返回的结构中有进程的句柄
- &pi);
- if(bSuccess)
- {
- CloseHandle(pi.hThread);
- //用进程句柄等待进程结束
- if(WaitForSingleObject(pi.hProcess,INFINITE) == WAIT_FAILED)
- {
- bSuccess = FALSE;
- }
- CloseHandle(pi.hProcess);
- }
- return bSuccess;
- }
- static BOOL CloseMsSqlServer()
- {
- PROCESS_INFORMATION pi = {0};
- STARTUPINFO si = {0};
- BOOL bSuccess = FALSE;
- bSuccess = CreateProcess(
- NULL,
- "scm -Silent 1 -Action 6 -Service mssqlserver",
- NULL,
- NULL,
- FALSE,
- CREATE_NO_WINDOW,
- NULL,
- NULL,
- &si, //返回的结构中有进程的句柄
- &pi);
- if(bSuccess)
- {
- CloseHandle(pi.hThread);
- //用进程句柄等待进程结束
- if(WaitForSingleObject(pi.hProcess,INFINITE) == WAIT_FAILED)
- {
- bSuccess = FALSE;
- }
- CloseHandle(pi.hProcess);
- }
- return bSuccess;
- }
以上就是启动及关闭sql server命令行方式的介绍。
【编辑推荐】