Inno Setup connection to the database and create

Source: Internet
Author: User
Tags dbase

Original Inno Setup connection to the database and create

Description:the first half in Inno Setup instance inside there, behind the database backup and restore in Side the instance is isn't easy to find online, I spent a great difficulty sentence try out, please Zhuanzhai marked to IND Icate 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 would Be asked to enter the server name, the name of the "you" see when you open the "SQL Server on" is different, as I as Sho WN 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 was in the Setup Wizard page, create a configuration database "butt On to procedure Sqldmobuttononclick (sender:tobject); var//used in some of the variables SQL Server, 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 SQL Server: = Createoleobject (' sql Dmo. SQL Server '); Except RaiseException (' You do not install ' the SQL database. ' # ' (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 Packag e-Want to reStore the database to find the backup file first and then find the backup file before the software installation to where we n Eed to know, which is the installation path. Installation in the registry to establish the relevant information, including software installation path recorded on the R Egistry, please see the above write the Inno SETUP Registry Add read. Why restore the "the" the "This" is, it seems to is around a circle, in fact, I also think, "This is not a good WA Y, but I don't know any other-path to get-the data in the installation-package (file paths) or software to is installed. {App}, {PF} such as this can is directly used, why do we have such a stupid. If any friends has a good-out, 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 (SQL Server); //Perform the restore Operation MsgBox (' database restore was successful! ', mbinformation, MB_OK); Except MsgBox (' database restore failed, 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 had to tell it When to perform. The finished installing, at the end of the Page button button, when this button is pressed, the Databas E 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 was to create a button to specify a parent window, which means that it displayed in which the top of the Pageparen T: = 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 Datab Ase' _at_ Sqldmobuttononclick); Top: = top + topinc; End

  

Inno Setup connection to the database and create

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.