您可以使用目录对象(ADOX)Create
的方法
试试这个示例应用
{$APPTYPE CONSOLE}
{$R *.res}
uses
ActiveX,
ComObj,
SysUtils;
procedure CreateSQLCeDatabase(const DataBase : string);
Var
Catalog : OleVariant;
begin
Catalog := CreateOleObject('ADOX.Catalog');
Catalog.Create(Format('Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=%s',[DataBase]));
end;
begin
try
CoInitialize(nil);
try
CreateSQLCeDatabase('C:\Data\Bar.sdf');
finally
CoUninitialize;
end;
except
on E:EOleException do
Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
on E:Exception do
Writeln(E.Classname, ':', E.Message);
end;
Writeln('Press Enter to exit');
Readln;
end.