Inno Setup connection to the database and create

本文涉及的产品
云数据库 RDS SQL Server,独享型 2核4GB
简介: 原文 Inno Setup connection to the database and create Description: the first half of this program in Inno Setup instance inside there, behind the dat...

原文 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;

  

相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情: https://www.aliyun.com/product/rds/sqlserver
目录
相关文章
|
2月前
|
关系型数据库 数据库 PostgreSQL
wikijs在启动项目时遇到的问题Database Initialization Error: create table “migrations“
wikijs在启动项目时遇到的问题Database Initialization Error: create table “migrations“
|
8月前
|
关系型数据库 MySQL 数据库
【报错】DVWA遇到Could not connect to the database service. Please check the config file. Database Error
【报错】DVWA遇到Could not connect to the database service. Please check the config file. Database Error
523 0
|
10月前
|
数据库
Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Could not create connection to database server. Attempted reconnect 3 times. Giving up.
112 0
|
SQL 数据库
CREATE DATABASE 语句
CREATE DATABASE 语句
100 1
|
SQL 存储 自然语言处理
Database Inside 系列 ——SQL 是如何执行的
Database Inside 系列 ——SQL 是如何执行的
99 0
Database Inside 系列 ——SQL 是如何执行的
|
JavaScript 关系型数据库 MySQL
|
关系型数据库 数据库 Oracle
12c:CREATE DATABASE——DBCA
界面1:Welcome     选择Create a Database,点击next 界面2:Step 2 of 14: Creation Mode     选择Advanced configuration,点击next 界面3:Step 3 of 14: Database Tem...
2017 0