Inno Setup connection to the database and create

时间:2022-04-26 23:04:17

原文 Inno Setup connection to the database and create

Description: the first half of this program in Inno Setup instance inside there, behind the database backup and restore inside the instance is not easy to find online, I spent a great difficulty sentence try out , please Zhuanzhai marked to indicate the respect of the individual labor. Thank you!

[Code] 

{--- SQLDMO ---} / / about SQLDMO of knowledge can go online 

const
/ / SQL server name, the name when installing SQL will be asked to enter the server name, the name you see when you open the SQL server on each machine is different, as I as shown below, but here we can use a generic The name is the (local) , Which means that the server is local. That's it. SQLServerName = '(LOCAL)';
SQLDMOGrowth_MB = 0; / / This is to create a button press event, this button is in the Setup Wizard page, create a configuration database "button
to procedure SQLDMOButtonOnClick (Sender: TObject);
var
/ / Used in some of the variables
SQLServer, Database, DBFile, LogFile: Variant;
IDColumn, NameColumn, Table, oBackup, oRestore: Variant;
db_path: string;
/ / Variable to store read the registry key value
ResultStr: String;
begin
{Create the main SQLDMO COM Automation object} / / Check if you installed SQL
try
SQLServer: = CreateOleObject ('SQLDMO.SQLServer');
except
RaiseException ('You did not install the SQL database.' # 13 # 13 '(Error''' + GetExceptionMessage +'' 'occurred)');
end; {Connect to the Microsoft SQL Server} / / Connect to SQL
SQLServer.LoginSecure: = True;
SQLServer.Connect (SQLServerName); / / MsgBox ('connection to SQL Server''' + SQLServerName +'' '.' MbInformation, MB_OK); {Setup a database} / / Create the SQL database file
Database: = CreateOleObject ('SQLDMO.Database');
Database.Name: = 'dbase'; / / To create a database name DBFile: = CreateOleObject ('SQLDMO.DBFile');
DBFile.Name: = 'ISData1';
/ / Database records
DBFile.PhysicalName: = 'c :/ program files / microsoft sql server / mssql / data / dbase_Data.MDF';
DBFile.PrimaryFile: = True;
DBFile.FileGrowthType: = SQLDMOGrowth_MB;
DBFile.FileGrowth: = 1; Database.FileGroups.Item ('PRIMARY'). DBFiles.Add (DBFile); LogFile: = CreateOleObject ('SQLDMO.LogFile');
LogFile.Name: = 'ISLog1';
/ / Database diary.
LogFile.PhysicalName: = 'c :/ program files / microsoft sql server / mssql / data / dbase_Log.LDF'; Database.TransactionLog.LogFiles.Add (LogFile); {Add the database} / / Add database
SQLServer.Databases.Add (Database); / / MsgBox ('Added database''' + Database.Name +'' '.', MbInformation, mb_Ok); / / Data backup
oBackup: = CreateOleObject ('SQLDMO.Backup'); / / create a backup object
oBackup.Database: = 'louyu'; / / To back up the database name
oBackup.Files: = 'f :/ louyu3.bak'; / / backup to
oBackup.BackupSetName: = 'louyu3.bak'; / / name of the backup
oBackup.BackupSetDescription: = 'bakDescription';
oBackup.Initialize: = true;
oBackup.SQLBackup (SQL Server); / / execute SQL backup operation / / Restore the data Highlights: / / Database backup file in a position to lay the package you want to restore the database to find the backup file first, then find the backup file before the software installation to where we need to know, which is the installation path. Installation in the registry to establish the relevant information, including software installation path recorded on the registry, please see the above write the INNO SETUP Registry Add read.
Why restore the database in this way, it seems to be around a circle, in fact, I also think that this may not be a good way, but I do not know any other way to get the data in the installation package ( file path) or software to be installed. {App}, {pf} such as this can not be directly used, why we have such a stupid way.
If any friends have a good way, please let me know. / / Get the installation path from the registry, according to the path found to restore the database backup file.
if RegQueryStringValue (HKLM, 'SOFTWARE / *******', 'Server', ResultStr) then
begin
ResultStr: = RemoveQuotes (ResultStr);
msgbox (resultstr, mbinformation, mb_ok);
try
oRestore: = CreateOleObject ('SQLDMO.Restore'); / / create a restore object
oRestore.Database: = 'dbase'; / / restore the database name
db_path: = resultstr + '/ database file / dbase.bak'; / / path of the backup file
The MsgBox (DB_PATH mbinformation, MB_OK); / / test to see the path right
oRestore.files: = db_path; / / Specify the backup file
oRestore.replacedatabase: = true;
oRestore.sqlrestore (sqlserver); / / perform the restore operation
MsgBox ('database restore was successful!', Mbinformation, MB_OK);
except
MsgBox ('database restore failed, please try again or consult the help documentation manual configuration!' Mbinformation, MB_OK);
end;
end;
end; / / Database creation and restore events finished, but it does not know when to perform intelligent, so we have to tell it when to perform. Here is the program is finished installing, At the end of the page BUTTON button, when this button is pressed, the database incident response.
{---}
/ / Create a button
procedure CreateButton (ALeft, ATop: Integer; ACaption: String; ANotifyEvent: TNotifyEvent);
begin
create with TButton.Create (WizardForm) do begin / / button object
Left: to = ALeft; / / Button's position and the width and height
Top: = ATop;
Width: = WizardForm.CancelButton.Width;
Height: = WizardForm.CancelButton.Height;
Caption: = ACaption; / / button name
OnClick: = ANotifyEvent;
/ / This is to create a button to specify a parent window, which means that it displayed in which the top of the page
Parent: = WizardForm.finishedPage; / / specified here is the end of the page of the form
end;
end; / / Initialization Wizard window
the procedure InitializeWizard ();
var
Left, Top, TopInc: Integer;
begin
Left: = WizardForm.WelcomeLabel2.Left;
TopInc: = WizardForm.CancelButton.Height + 8;
Top: = WizardForm.WelcomeLabel2.Top + WizardForm.WelcomeLabel2.Height - 4 * TopInc;
/ / Created above button displayed, and assign it a response event
CreateButton (Left, Top, '& configuration SQL database' _AT_ SQLDMOButtonOnClick);
Top: = Top + TopInc;
end;

  

Inno Setup connection to the database and create的更多相关文章

  1. INNO SETUP数据库的连接与创建

    原文:INNO SETUP数据库的连接与创建 说明一下:这块程序的前半部分在INNO SETUP的实例里面就有,而后面如果对数据库进行备份和还原在实例里面没有,在网上也不好找,是本人费了好大劲一句一句 ...

  2. 用Inno Setup制作WEB程序安装包

    原文 用Inno Setup制作WEB程序安装包 最近做了一个WEB程序的安装包,我把制作的过程做个介绍,贴出源码给大家做个参考 看看inno 的脚本 [Setup] AppCopyright=tes ...

  3. 【转载】inno setup 水波纹效果,检测安装vcredist_x86.exe等

    以下inno setup脚本,实现了:1.水波纹效果 2.安装时检测是否安装其他版本,并在欢迎页面添加文字提示 4.检测安装vcredist_x86.exe  3.卸载时添加提示 ; 脚本由 Inno ...

  4. 一个简单的inno setup模板

    一.模板代码 基本功能包括多路径安装.多语言.自定义图标. [Setup] ShowLanguageDialog=yes AppCopyright=Copyright Reserved(C) , 36 ...

  5. Inno Setup怎样创建一个自动申请管理员身份运行的快捷

    如果你使用的是 Unicode 版本的 Inno Setup,那么以下是更为专业的解决方法.    这是 mlaan 提及的再一种方法. QUOTE(     CodeAutomation3.iss) ...

  6. 以前编写的inno setup脚本,涵盖了自定义安装界面,调用dll等等应用 (转)

    以前编写的inno setup脚本,涵盖了自定义安装界面,调用dll等等应用 (转) ; Script generated by the Inno Setup 脚本向导. ; SEE THE DOCU ...

  7. Inno Setup使用技巧

    一.关于Inno Setup如何在安装时播放音乐 方法(1): 在脚本编译里的[Code]与[Files]段处添加以下代码: [Code] Function mciSendString(lpszCom ...

  8. 用inno Setup做应用程序安装包的示例脚本(.iss文件)(

    用innoSetup做应用程序安装包的示例脚本(.iss文件),具体要看innoSetup附带的文档,好象是pascal语言写的脚本. 示例1(应用程序.exe,客户端安装): ;{089D6802- ...

  9. inno setup介绍及官方网站地址

    使 用 笔 记 1.Inno Setup 是什么?Inno Setup 是一个免费的 Windows 安装程序制作软件.第一次发表是在 1997 年,Inno Setup 今天在功能设置和稳定性上的竞 ...

随机推荐

  1. C++11新特性总结 (一)

    1. 概述 最近在看C++ Primer5 刚好看到一半,总结一下C++11里面确实加了很多新东西,如果没有任何了解,别说自己写了,看别人写的代码估计都会有些吃力.C++ Primer5是学习C++1 ...

  2. iOS - Swift 数据持久化

    1.Sandbox 沙箱 iOS 为每个应用提供了独立的文件空间,一个应用只能直接访问为本应用分配的文件目录,不可以访问其他目录,每个应用自己独立的访问空间被称为该应用的沙盒.也就是说,一个应用与文件 ...

  3. Oracle 日期计算

    日期相减,求天数 方法一: )),createdate from goods t

  4. topshelf和quartz

    topshelf和quartz内部分享 阅读目录: 介绍 基础用法 调试及安装 可选配置 多实例支持及相关资料 quartz.net 上月在公司内部的一次分享,现把PPT及部分交流内容整理成博客. 介 ...

  5. 二阶段项目所遇问题 如何实现php向js传输数据

    首先当前页面做了一个双处理的界面,就是有PhP也有JS的处理界面. 上一个传值界面是一个PHP的传值,结果,在当前页面的JS中也要用到上一界面传的值,这时发现,PHP与JS就像是两个互相孤立的小岛,根 ...

  6. 分享Sql Server 2008 r2 数据备份,同步服务器数据(一.本地备份)

    最近在部署一个系统,处于数据安全的考虑,因此对相应的数据库服务器定时备份,以及数据同步到备份服务上.之前在另外的一个项目中也做过相应的操作,但是操作都是按照查找到的文章一步一步的操作,碰到一些细节问题 ...

  7. [Swift]Xcode标记:MARK、TODO、FIXME

    1. MARK MARK一定要大写.其又叫做代码标注,我们可以使用它来添加一些说明文字.同时可以选择其上方是否需要显示分割线. // MARK: - 说明文字,带分割线 // MARK: 说明文字,不 ...

  8. 万恶之源 - Python模块一

    序列化 我们今天学习下序列化,什么是序列化呢? 将原本的字典.列表等内容转换成一个字符串的过程就叫做序列化. 为什么要有序列化模块: 比如,我们在python代码中计算的一个数据需要给另外一段程序使用 ...

  9. Vue filter-v-for 使用

    var app5 = new Vue({ el: '#app5', data: { shoppingList: [ "Milk", "Donuts", &quo ...

  10. How to Create Triggers in MySQL

    https://www.sitepoint.com/how-to-create-mysql-triggers/ I created two tables: CREATE TABLE `sw_user` ...