inno setup 执行SQL

参考之:
1.可将导入数据的功能写入一个小程序,再外部调用(楼上已经说了);
2.可用程序代码:
[Setup]
AppName=科發醫院管理系統
AppVerName=科發醫院管理系統4.0
AppPublisher=廣州科發科技有限公司
AppPublisherURL=http://www.kf200.com
AppSupportURL=http://www.kf200.com
AppUpdatesURL=http://www.kf200.com
DefaultDirName={pf}科發醫院資訊管理系統
DefaultGroupName=科發醫院管理系統
;LicenseFile=.SoruceProgramYygl使用者授權合約.txt
Comdivssion=bzip
SolidComdivssion=no

[Types]
Name: "full"; Description: "完整安裝"
Name: "custom"; Description: "自訂安裝"; Flags: iscustom

[Components]
Name: "program"; Description: "全部程式"; Types: Custom
;Name: "ProgramHis"; Description: "醫院執行資訊系統"; Types: full
;//Custom
;//Name: "programClientSet"; Description: "用戶端"; Types: full
Name: "programKfpt"; Description: "二次開發平臺"; Types: Custom
;Name: "programCzsc"; Description: "操作手冊"; Types: Custom
;//full Custom
Name: "programServerApp"; Description: "後臺服務控制器"; Types: Custom
Name: "readme"; Description: "讀我檔案"; Types: full


[Tasks]
; 注意: 下面的條目包含一個中文用語 (“創建桌面快捷方式”和“添加快捷方式”)。如果需要你可以翻譯為其它語言。
Name: "desktopicon"; Description: "創建桌面快捷方式"; GroupDescription: "添加快捷方式:"; Flags: unchecked
;//unchecked

[Files]
Source: ".SoruceProgramkfpt*"; DestDir: "{app}"; components :programkfpt ;Flags: ignoreversion recursesubdirs
Source: ".SoruceProgramServerApp*"; DestDir: "{app}"; components :programServerApp ;Flags: ignoreversion recursesubdirs
Source: ".SoruceData*.*"; DestDir: "{drive:{app}}Data"

; 注意: 不要在任何共用系統檔中使用“Flags: ignoreversion”

[Icons]
Name: "{group}後臺服務控制器"; Filename: "{app}ServerApp.exe" ;WorkingDir: "{app}" ;components :programServerApp
Name: "{group}二次開發平臺"; Filename: "{app}KfPt.exe" ;WorkingDir: "{app}" ;components :programkfpt
; 注意: 下面的條目包含一個中文用語 (“卸載”)。如果需要你可以翻譯為其它語言。
Name: "{group}卸載 科發醫院管理系統"; Filename: "{uninstallexe}"

[Run]
; 注意: 下列條目包含一個中文用語 (“運行”)。如果需要你可以翻譯為其它語言。

[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}DatalinkDefLink.udl'),True);

end;
end;

原文地址:https://www.cnblogs.com/zhangzhifeng/p/6069221.html