-------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
procedure Tdatasetting.FlatButton1Click (Sender: TObject); begin ADOQuery1.Close; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add ( 'backup database hrdb to disk =' '' '' FlatEdit1.Text '' ''); AdoQuery1.execsql; showMessage ('data is successful in successful backup!'); Datasetting.Close;
procedure Tdatares.FlatButton1Click (Sender: TObject); begin ADOQuery1.Close; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add ( 'restore database hrdb from disk =' '' '' FlatEdit1.Text '' ''); AdoQuery1.execsql; showMessage ('data is successfully restored!'); Datares.close;
- Have an exception information try adoquery1.close; adoquery1.sql.clear; adoQuery1.sql.add ('backup Database DatabaseName to DataDataDevice'); adoQuery1.exec; Except ON E: Exception ShowerRor ('Backup Failure:' E. Message);
SQL Server Database File Recovery Technology YZHSHI (YZHShi@etang.com)
There are two ways for SQL Server database backups, one is to back up the database file using Backup Database, and the other is to copy database files MDF and log files LDF. The backup and recovery of the latter will be discussed below. This article assumes that you can skilled using SQL Server Enterprise Manager (SQL Server Enterprise Manager) and SQL Server Quwey Analynser (SQL Server Query Analyzer)
1. Normal backup, recovery mode Under normal mode, we have to back up a database, first to interrupt the database from the running data server, or stop the entire database server, then copy the file. Remove the database command: Sp_detach_db database name of the database command to connect: Sp_attach_db or sp_attach_single_file_dbs_attach_db [@dbname =] 'dbname', [@ filename1 =] 'filename_n' [, ... 16] sp_attach_single_file_db [@dbname =] 'dbname' [@physName =] 'physical_name' Use this method to properly restore the database files of SQL Sever7.0 and SQL Server 2000, and you must back up both files when you back up, MDF files are database data. File, LDF is a database log file. Example: Suppose the database is TEST, its data file is test_data.mdf, log file is Test_log.ldf. Let's discuss how to back up and restore this database. Removing the database: sp_detach_db 'test' connection database: sp_attach_db 'test', 'c: / program files / microsoft SQL Server / MSSQL / DATA / TEST_DATA.MDF', 'C: / Program Files / Microsoft SQL Server / MSSQL / DATA / Test_log.ldf'sp_attach_single_file_db 'Test', 'C: / Program Files / Microsoft SQL Server / MSSQL / DATA / TEST_DATA.MDF'2, only MDF file recovery technology Due to various reasons, if we only backed up MDF files at the time, So restored is a very troublesome thing. If your MDF file is generated by the current database, it is very lucky, maybe you can recover the database using sp_attach_db or sp_attach_single_file_db, but will appear similar to the following prompt information
Device activation errors. Physical file name 'C: / program files / microsoft SQL Server / MSSQL / DATA / TEST_LOG.LDF' may be wrong. A new log file named 'C: / Program Files / Microsoft SQL Server / MSSQL / DATA / TEST_LOG.LDF' has been created.
However, if your database file is copied from other computers, it is very unfortunate, perhaps the above method does not work. You may get the following error message
Server: Message 1813, Level 16, State 2, Row 1 Failed to open the new database 'test'. CREATE DATABASE will terminate. Device activation errors. Physical file name 'd: /test_log.ldf' may be incorrect.
How to do it? Don't worry, let's explain the recovery approach. A. We use the default way to create a database (such as Test) for recovery. Can be established in SQL Server Enterprise Manager. B. Stop the database server. C. Remove the log file Test_log.ldf you just generated, override the database data file Test_Data.mdf you just generated with the database MDF file you want to recover. D. Start the database server. At this time, you will see the status of the database TEST is "Troubleshoot". This will not do anything about this database. E. Setting the database to allow direct operating system tables. This action can select the database server in SQL Server Enterprise Manager, press Right-click, select "Properties", and "Allow Direct Modifications to System Directory" in the Server Settings page. You can also use the following statement to be used. Use master go sp_configure 'allow updates', 1 Go Reconfigure with override gof. Set TEST for emergency repair mode Update sysdatabases set status = -32768 where dbid = db_id ('test') can see the database in SQL Server Enterprise Manager can see the database in "Read / quenus / offline / emergency mode" Go to the table in the database, but just system table G. In the execution of the true recovery operation, rebuild database log file DBCC Rebuild_log ('Test', 'C: / Program Files / Microsoft SQL Server / MSSQL / DATA / TEST_LOG.LDF') If you encounter the following prompt information: Server : Message 5030, Level 16, State 1, Row 1 Fails to lock the database to perform this operation. DBCC is executed. If DBCC outputs an error message, contact your system administrator.
Note that your other programs are using the database. If you just open the Test library system table in F step, you can use the SQL Server Enterprise Manager. The prompt to perform correctly is similar to:
Warning: The log 'Test' log has been rebuilt. The consistency of the transaction has been lost. DBCC CHECKDB should be run to verify physical consistency. The database option must be reset, and you may need to delete an extra log file. DBCC is executed. If DBCC outputs an error message, contact your system administrator. This time, open in SQL Server Enterprise Manager will see the status of the database is "for DBO only". At this point you can access the user table inside the database. H. Verify database consistency (omitted) DBCC CHECKDB ('test') General execution results are as follows: checkdb found 0
-------------------------------------------------- -------------------------------------- SQL-DMO programming
SQL-DMO file: SqldMo.dll: DLL to implement SQL-DMO object; SqldMo.Rll: Localized resource file; SqldMo.h: Member function, type, type, enumeration data type, and macros of SQL-DMO; C / C File; SQLDMOID.H: Contains the C / C header file of the interface and class identifier. You seem to be right, your DMO, DB, TB don't know each other: Procedure TForm1.Button1Click (Sender: Tobject); VARDMO, DB, TB: Olevariant; str: string; begin DMO: = CreateoleObject ('Sqldmo.sqlserver'); DB: = CreateoleObject ('sqldmo.database'); TB: = CreateoleObject ('sqldmo.table'); DMo.connect ('WHO', 'SA', ''); DB: = DMo.databases.Item ('pubs'); TB: = db.tables.item ('Jobs'); str: = tb.script (); showMessage (str); end; in W2000 D6 SQL2000 is no problem
Address: If you use CreateoleObject, you won't be wrong, why?
Var lsqlserver: olevariant; begin lsqlser: = createoleObject ('sqldmo.sqlserver.8.0'); LSQLServer.connect ('192.168.6.26', 'sa', 'Net026');. . . . . . End.
Using SQL Server2000 DMO Using Delphi: How to Import SqldMo.dll into ActiveX Control? Why is it wrong when using Delphi auto-generated control? How does its event trigger if the original object is used?
SQLDMO.DLL is not ActiveX control, can not be converted to an ActiveX control? In Project-Import Type Library, you can import a generated unit file is too big, there are more than 4M, I have not succeeded with D6.
Note when importing, if you have an error, you don't need to manage it, you can use the unit files generated in your engineering.
I use the SQL Server DMO object to compress the SQL Server Lof file. It is not very clear to see if I need myself.
Uses sqldmo_tlb; var svr: _sqlser; dbs: databases; db: _database;
Logs: Logfiles; log: _logfile;
Procedure TForm1.Button1Click (Sender: TOBJECT); VAR i: integer; p: prot: = cosqlser.create (); svr.connect ('Bruce', 'SA', EMPTYPARAM); // Connect to SQL Server Database // Parameters: _SQLServer.Connect (& Server Name &, & User Name &, & Password &); DBS: = Svr.databases; for i: = 1 to dbs.count do begin if (dbs.itembylid (i) .name = 'DFW' ) The begin db: = dbs.itembylid (i); break; end; end; // Select the name object of DFW from SQL Server - DB
Tlog: = db.transactionLog; logs: = tlog.logfiles; // Get logfiles objects from _Database
For i: = 1 to logs.count do begin if (logs.item (i) .name = 'dfw_log') Then Begin log: = logs.Item (i); Break; end; end; // From the logfiles object Select _Logfile objects named DFW_LOG - LOG
Log.shrink (10, EMPTYPARAM); // Complicates the log file to 10m or less
SVR: = NIL; END;
-------------------------------------------------- ---------------------------------------
-------------------------------------------------- --------------------------------------- When making the SQL Server database data backup and recovery How to display progress bar? It is backup and recovered using the SQL statement.
You can try to set the data set as an asynchronous manner, so the data set provides two events to progress (one is progress, a completion), the specific help. ----------- -------------------------------------------------- ----------------------------