我是这样执行的osql脚本,但是要报错 parameter object is improperly defind. Inconsistent or incomplete information was provided 大家帮我看看 with ADOQuery1 do begin Close; SQL.Clear; SQL.LoadFromFile('C:\333.sql'); ExecSQL; end;
这样一定可以我已经试过了:procedure TForm1.Button1Click(Sender: TObject); var SqlStr,Tmp:string; F:TextFile; begin assignfile(F,'d:\test.sql'); reset(f); Repeat Readln(F,tmp); if tmp='GO' then begin adoconnection1.Execute(sqlstr); sqlstr:=''; tmp:=''; end; sqlstr:=sqlstr+tmp+chr(13)+chr(10); Until eof(F); closefile(F);
如果是SQL server数据,你可以连接Master库,再执行建表和存储过程的脚本。
adoquery.sql.clear;
adoquery.sql.add(加在这里);
adoquery.open;
sSql:string
begin
sSql := 'select ..........';
adoquery.close;
adoquery.sql.clear;
adoquery.sql.add(sSql);
adoquery.open;
end;
begin
Close;
SQL.Clear;
SQL.LoadFromFile('yoursqlfile');
ExecSQL;
end;
大家看看!
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.ADD('Create datebase hhh');
ExecSQL;
end;
DROP DATABASE [tttt]
GOCREATE DATABASE [tttt] ON (NAME = N'tttt_Data', FILENAME = N'd:\sql_data2\MSSQL\data\tttt_Data.MDF' , SIZE = 2, FILEGROWTH = 10%) LOG ON (NAME = N'tttt_Log', FILENAME = N'd:\sql_data2\MSSQL\data\tttt_Log.LDF' , SIZE = 1, FILEGROWTH = 10%), (NAME = N'www', FILENAME = N'e:\www_Log.LDF' , SIZE = 1, FILEGROWTH = 10%)
COLLATE Chinese_PRC_CI_AS
GOexec sp_dboption N'tttt', N'autoclose', N'false'
GOexec sp_dboption N'tttt', N'bulkcopy', N'false'
GOexec sp_dboption N'tttt', N'trunc. log', N'false'
GOexec sp_dboption N'tttt', N'torn page detection', N'true'
GOexec sp_dboption N'tttt', N'read only', N'false'
GOexec sp_dboption N'tttt', N'dbo use', N'false'
GOexec sp_dboption N'tttt', N'single', N'false'
GOexec sp_dboption N'tttt', N'autoshrink', N'false'
GOexec sp_dboption N'tttt', N'ANSI null default', N'false'
GOexec sp_dboption N'tttt', N'recursive triggers', N'false'
GOexec sp_dboption N'tttt', N'ANSI nulls', N'false'
GOexec sp_dboption N'tttt', N'concat null yields null', N'false'
GOexec sp_dboption N'tttt', N'cursor close on commit', N'false'
GOexec sp_dboption N'tttt', N'default to local cursor', N'false'
GOexec sp_dboption N'tttt', N'quoted identifier', N'false'
GOexec sp_dboption N'tttt', N'ANSI warnings', N'false'
GOexec sp_dboption N'tttt', N'auto create statistics', N'true'
GOexec sp_dboption N'tttt', N'auto update statistics', N'true'
GOif( ( (@@microsoftversion / power(2, 24) = 8) and (@@microsoftversion & 0xffff >= 724) ) or ( (@@microsoftversion / power(2, 24) = 7) and (@@microsoftversion & 0xffff >= 1082) ) )
exec sp_dboption N'tttt', N'db chaining', N'false'
GOuse [tttt]
GO
这是完整的创建数据库的SQL语句,在SQL中能运行,说明你的语句没错,在程序中运行,需要考虑登陆权限等。
另,
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.ADD('Create datebase [hhh]');
ExecSQL;
end;
----
winexec('osql -S. -Usa -P -ipath\aa.sql',1);
parameter object is improperly defind. Inconsistent or incomplete information was provided
大家帮我看看
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.LoadFromFile('C:\333.sql');
ExecSQL;
end;
你不可能连SQL Server客户引擎都不装吧,如果将了的话,
就可以用osql来执行本地的SQL Server导出的建库的文件,而用TQuery来执行是受限制的,
因为SQL Server导出的文件中,
有很多在TQuery中无法执行,比如GO,如果你安装了SQL Server客户端,可以在CMD中运行osql,自己看看它的帮助,
osql -S"servername" -U"username" -P"password" -i"C:\MyWorkZone\createdb.sql"
-P参数后密码是明文的,
如果你保存配置文件,要小心一点了。
var
SqlStr,Tmp:string;
F:TextFile;
begin
assignfile(F,'d:\test.sql');
reset(f);
Repeat
Readln(F,tmp);
if tmp='GO' then
begin
adoconnection1.Execute(sqlstr);
sqlstr:='';
tmp:='';
end;
sqlstr:=sqlstr+tmp+chr(13)+chr(10);
Until eof(F);
closefile(F);