procedure TForm1.Button1Click(Sender: TObject);
begin
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog= ' + '''master''' + ';Data Source= '+ '''LSH''';
ADOConnection1.Connected:=true;
ADOQuery1.Connection:=ADOConnection1;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select * from sysdatabases where name:=''YMQSQL''';
ADOQuery1.Open;
end;我的服务器是:LSH
ADOConnection1 连接的数据库是:master我想查询 master 中的 sysdatabases 表中是否有 YMQSQL 数据各位大哥,我是哪里写错了啊?谢谢!
begin
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog= ' + '''master''' + ';Data Source= '+ '''LSH''';
ADOConnection1.Connected:=true;
ADOQuery1.Connection:=ADOConnection1;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select * from sysdatabases where name:=''YMQSQL''';
ADOQuery1.Open;
end;我的服务器是:LSH
ADOConnection1 连接的数据库是:master我想查询 master 中的 sysdatabases 表中是否有 YMQSQL 数据各位大哥,我是哪里写错了啊?谢谢!
要改为
ADOQuery1.SQL.Text:='select * from sysdatabases where name=''YMQSQL''';
多个了冒号
还请
procedure TForm1.Button2Click(Sender: TObject);
begin
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog= ' + '''master''' + ';Data Source= '+ '''LSH''';
ADOConnection1.Connected:=true;
ADOQuery1.Connection:=ADOConnection1;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select * from sysdatabases where name=''YMQSQL''';
ADOQuery1.SQL.Text:='ALTER DATABASE ''test'' SET OFFLINE WITH ROLLBACK IMMEDIATE';
ADOQuery1.ExecSQL;
end;我需要把 test 数据库分离掉
可是单击 Button2 ,提示:
第一行 'test' 附近有语法错误
各位大哥,我是错在哪里啊?谢谢!
楼上所言甚是!
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog= ' + '''master''' + ';Data Source= '+ '''LSH''';
ADOConnection1.Connected:=true;
ADOQuery1.Connection:=ADOConnection1;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='restore database test from ''backup3''';
try
ADOQuery1.ExecSQL;
showmessage('成功');
except
showmessage('失败');
end;
我单击 button 按钮时提示:
backup3 附件有错误, backup3 是一个备份设备!
(已经备份了 test 数据库)各位大哥,我是错在哪里啊?谢谢!