高分紧急求救(在VC。NET中调用SQLSERVER中的OSQL执行一个含SQL语句的文件
本人想调用SQLSERVER里的查询分析器执行一个sql.sql的文件,但运行失败,可能是参数设置不对,望高人指点
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = "open";
ShExecInfo.lpFile = _T("osql");
ShExecInfo.lpParameters =" -u sa -p sql -d dbname -i c:\sql.sql";//传入命令行参数
ShExecInfo.lpDirectory =NULL;//指定工作目录(如果为NULL当前工作目录)
//ShExecInfo.lpDirectory="C:\\Program Files\\Microsoft SQL Server\\80\\Tools\\Binn";
ShExecInfo.nShow = SW_HIDE;//隐藏执行
ShExecInfo.hInstApp = NULL;
//3)执行
//ShellExecuteEx函数调用成功会返回TRUE,否则返回FALSE
if(!ShellExecuteEx(&ShExecInfo))
return FALSE;
if(WAIT_FAILED==WaitForSingleObject(ShExecInfo.hProcess,INFINITE))
return FALSE;