查询分析器Go语句

查询分析器是sql客户端,它可以识别go用来分批提交,但go不是sql语句,sql服务器不能识别所以不能用在程序中。

启用SQL自动备份

function get_sql_ver(): Integer; //判断当前SqlServer版本

var

AQ: TADOQuery;

ver: string;

begin

AQ := tadoquery.Create(nil);

AQ.Connection := fdm.ADOCon;

AQ.SQL.Text := 'master..xp_msver ProductVersion';

AQ.Open;

if AQ.RecordCount > 0 then

begin

ver := AQ.FieldValues['Character_Value'];

result := strtoint(leftstr(ver, pos('.', ver) - 1));

end

else

Result := 0;

AQ.close;

AQ.free;

end;

if get_sql_ver() > 8 then //sql2005以上版本需开启cmd开关才能运行

begin

lvtmp := Tstringlist.Create;

try

// EXEC sp_configure 'show advanced options', 1 GO

// RECONFIGURE GO

// EXEC sp_configure 'xp_cmdshell', 1 GO

// RECONFIGURE GO

// master..xp_cmdshell 'sc config SQLSERVERAGENT start= auto'

// EXEC sp_configure 'xp_cmdshell', 0 GO

// RECONFIGURE GO

lvtmp.Clear;

lvtmp.Add('EXEC sp_configure ''show advanced options'', 1 ');

lvtmp.Add('RECONFIGURE ');

lvtmp.Add('EXEC sp_configure ''xp_cmdshell'', 1 ');

lvtmp.Add('RECONFIGURE ');

lvtmp.Add('EXEC master..xp_cmdshell ''' + cmd + ''' ');

lvtmp.Add('EXEC sp_configure ''xp_cmdshell'', 0 ');

lvtmp.Add('RECONFIGURE ');

Result := lvtmp.Text;

finally

lvtmp.Free;

end;

end

else

Result := 'master..xp_cmdshell ''' + cmd + ''' ';

posted @ 2018-01-10 06:40  后凤凰  阅读(129)  评论(0编辑  收藏  举报