Recommended: ASP 3.0 Advanced Programming (45) Asynchronous execution refers to retrieving data in the background, and the data you have obtained can be used on the web page before all the data is returned. Although all data may be needed, asynchronous work can start processing data at least in advance. It can also allow users to see certain content first, which makes the Web site
Overview
SQL Distributed Management objects (SQL-DMO) provide developers with methods to perform ordinary tasks using program and scripting languages, thus extending the functionality of SQL Server. This article discusses how to cleverly use SQL-DMO to create database backup and verification ASP applications.
premise
You need to have the knowledge about SQL Server database backup. In addition, you need to add a reference to the SQL-DMO library to the global.asa file. The following is a reference to SQL Server 2000:
| The following is the quoted content: <!--METADATA TYPE=TypeLib NAME=Microsoft SQLDMO Object Library UUID= {10010001-E260-11CF-AE68-00AA004A34D5} VERSION=8.0--> |
This article's sample code is applicable to SQL 7.0, MSDE, and SQL Server 2000.
Joy and sorrow
Using SQL-DMO objects makes people happy and sad. It provides so rich features that it is not known how to use it. This article only discusses the object properties and methods involved in the examples. You can find a lot of relevant information on SQL Server online teaching.
SQLDMO.SQLServer
Used to connect to SQL Server database:
| The following is the quoted content: <% Dim srv Set srv = Server.CreateObject(SQLDMO.SQLServer) srv.LoginTimeout = 15 srv.Connect servername, username, password %> |
Here, the SQL Server database is connected by substituting the username and password. If you want to use NT's identity authentication, set its LoginSecure property to True (TRUE), ignore the substituted username and password, and use NT's registration information.
SQLDMO.Database
Lists the databases in the server. In this example, the listed database is backed up. The following code lists the database in the server in the drop-down menu:
| The following is the quoted content: <% Dim srv Dim objDB Set srv = Server.CreateObject(SQLDMO.SQLServer) srv.LoginTimeout = 15 srv.Connect servername, username, password Set objDB = Server.CreateObject(SQLDMO.Database) %> <SELECT name=fdatabase> <% For Each objDB In srv.Databases If objDB.SystemObject = False Then %> <OPTION><%=objDB.Name%></OPTION> <% End If Next %> </SELECT> |
SQLDMO.BackupDevice
Lists the backup devices installed on the server. I recommend using a backup device to back up the database. Because this way, you can use the verification function of SQL-DMO to verify the backup situation. The following code lists the backup devices on the server:
| The following is the quoted content: <% Dim srv Dim objDevice Set srv = Server.CreateObject(SQLDMO.SQLServer) srv.LoginTimeout = 15 srv.Connect servername, username, password Set objDevice = Server.CreateObject(SQLDMO.BackupDevice) For Each objDevice In srv.BackupDevices Response.Write objDevice.Name <BR> Next %> |
SQLDMO.Backup
This is what we want to use to backup core objects. It has many properties that allow us to make backups at the same level as the Enterprise SQL Manager. Let’s first discuss the properties used in this example.
BackupSetName - Backup file name.
Database - The database to be backed up.
Action - All or incremental backups. There are other options, but only these two are used in the example.
BackupSetDescription - Backup Description.
Files - File backup options. Indicates the path and name of the backup file, such as: C:/pubs.bak. When using file backup, the following backup device name should be set to empty.
Devices - Backup device on the server. If you are using a backup device, the file backup option above should be set to empty.
TruncateLog - Backup log option. The options are:
NoLog - No transaction log backup.
NoTruncate - Backup transaction logs. Time marks are provided in the log.
Truncate - Backup transaction logs, but not keep transaction records.
Initialize - If set to True, the backup device will replace other backup media and become the first choice.
Here is the backup.asp file in the example:
| The following is the quoted content: <%@ Language=VBScript %> <HTML> <BODY> <!--contains all the login information --> <!--#include file=login.asp --> <% Dim objBackup 'Create backup object set objBackup = Server.CreateObject(SQLDMO.Backup) 'Set properties objBackup.BackupSetName = Request(fname) objBackup.Database = Request(fdatabase) objBackup.Action = Request(fAction) objBackup.BackupSetDescription = Request(fdescription) objBackup.Files = Request(fbackupfile) objBackup.Devices = Request(fdevice) objBackup.TruncateLog = Request(flog) objBackup.Initialize = Request(finit) 'Backup database objBackup.SQLBackup srv 'Disconnect from the server srv.disconnect 'release set srv = nothing set objBackup = Nothing %> <P> The backup was started, use the <A HREF=devices.asp>verify</A> option to see if it completed successfully. <A HREF=default.asp>Click here</A> to return. </P> </BODY> </HTML> |
Backup verification
If you are programming in VB or C, you can use event triggers to verify the backup process, but not in ASP. We use the ReadBackupHeader method of the SQLDMO.BackupDevice object to confirm whether the backup is successful.
Below is the verification.asp file code, which lists the name of the backup device and provides information about the most recent backup.
| The following is the quoted content: <%@ Language=VBScript %> <HTML> <BODY> <!--Login information --> <!--#include file=login.asp--> <P> <% Dim objDevice Dim objResults Dim iCount Dim xCount 'Create backup device object Set objDevice = Server.CreateObject(SQLDMO.BackupDevice) 'Loop until a matching device is found For Each objDevice In srv.BackupDevices If objDevice.Name = Request(fname) Then 'Find the matching device and start reading the result Set objResults = objDevice.ReadBackupHeader For iCount = 1 To objResults.Rows For xCount = 1 To objResults.Columns%> <B><%=objResults.ColumnName(xcount)%></B>: <%=objResults.GetColumnString(icon,xcount)%><br> <%Next %> <HR> <%Next %> <%End If%> <%Next%> <% srv.Disconnect set srv = nothing set objDevice = nothing set objResults = nothing %> </BODY> </HTML> |
The ReadBackupHeader method returns the QueryResults object. Use its Rows attribute to get the backup record number. Then search for column information for each row of records.
Other features
SQL-DMO also provides remote backup and recovery capabilities. This article does not involve database recovery, but SQL-DMO has strong recovery functions.
Share: Basic Development Entry Level: Comparison between JSP and ASP Since Microsoft launched ASP (ActiveServerPage), it has been loved by WEB developers for its powerful functions and simplicity and easy to learn. However, it has common problems with Microsoft products and can only be used on Windows platforms, although it can be used in LINUX by adding controls