inno setup 附加数据库方法
[Code]
{--- SQLDMO ---}
const
SQLServerName = '(local)';
SQLDMOGrowth_MB = 0;
procedure InstallDb();
var
SQLServer, Database, DBFile, LogFile: Variant;
IDColumn, NameColumn, Table: Variant;
FlagDbExist:Boolean;
FileName1, Filename2,DbName,DbPath:String;
begin
//;if MsgBox('安装程序现在将通过一个可信任的连接到 Microsoft SQL 服务器 ''' + SQLServerName + ''' 并创建一个数据库。你想继续吗?', mbInformation, mb_YesNo) = idNo then
// Exit;
{ 创建主 SQLDMO COM 自动操作对象 }
try
SQLServer := CreateOleObject('SQLDMO.SQLServer');
except
RaiseException('未安装数据库服务器,先请安装 Microsoft SQL Server 服务器。'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)');
exit;
end;
{ 连接到 Microsoft SQL 服务器 }
DbName:='KfHis_std_a';
//私营版
SQLServer.LoginSecure := True;
SQLServer.Connect(SQLServerName);
//MsgBox('已连接到 Microsoft SQL 服务器 ''' + SQLServerName + '''.', mbInformation, mb_Ok);
{ 安装数据库 }
FlagDbExist:=True;
Database := CreateOleObject('SQLDMO.Database');
try
Database := SQLServer.Databases.Item(DbName);
except
FlagDbExist:=False;
end;
if FlagDbExist=False then
else
exit; {数据库已安装}
FileName1:= ExpandConstant('{drive:{app}}/Data')+'/KFHIS.mdf';
Filename2:= ExpandConstant('{drive:{app}}/Data')+'/KFHIS_log.ldf';
{附加数据库}
dbPath:= FileName1+' , '+Filename2;
try
SQLServer.AttachDB(DBName, dbPath);
except
MsgBox('数据库安装失败!', mbInformation, mb_Ok);
exit;
end;
MsgBox('数据库安装成功!', mbInformation, mb_Ok);
end;
function InitializeSetup(): Boolean;
begin
{ MsgBox('aa', mbInformation, mb_Ok); }
Result:=True;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
{ if CurPageID=wpInfoAfter then
begin
MsgBox('pageid'+inttostr(CurPageID),mbInformation, mb_Ok);
InstallDb();
end; }
Result:=True;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep=ssPostInstall then
begin
InstallDb();
CreateDir(ExpandConstant('{app}/Datalink'));
FileCopy(ExpandConstant('{app}/DefLink.udl'),ExpandConstant('{app}/Datalink/DefLink.udl'),True);
end;
end;