asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Code Samples
Components
Tools
New
Free
Downloads
Vendors
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Backing Up A Database

Create a stored procedure mydbackup as

BACKUP mydb to DISK='c:\mtdb.bak'

In SQLDMO, an example:


Set srv=Server.CreateObject("SQLDMO.SQLServer")
srv.Connect "servername", "username", "password"
Set bak = Server.CreateObject("SQLDMO.Backup")
bak.Database="Northwind"
bak.Devices=Files
bak.Files="e:\nwind.bak"
bak.SQLBackup srv
Response.write "DONE!"

Restoring A Database

In a stored procedure:

RESTORE DATABASE Northwind FROM DISK='c:\nwind.bak' [WITH ]

In SQLDMO you use the restore object (check BOL for full syntax):


Set srv=Server.CreateObject("SQLDMO.SQLServer")
srv.Connect "servername", "username", "password"
Set rest=Server.CreateObject("SQLDMO.Restore")
rest.Action=0 ' full db restore
rest.Database="Northwind"
rest.Devices=Files
rest.Files="c:\nwind.bak"
rest.ReplaceDatabase=True 'Force restore over existing database
rest.SQLRestore srv

response.write "Done!"

set rest=nothing
set srv=nothing

More details can be found in BOL (has the SQLDMO object model) and there's an article here http://www.asp101.com/articles/carvin/sqldmobackup/default.asp.

Submitted by Jasper Smith on the ASP e-mail discussion list.



email this code sample to a colleague

Related Products
FileSystemObject
The FileSystemObject group is a set of COM objects that allow you to manipulate the file system on from an Active Server Page. FileSystemObject which is documented here is the version that comes with IIS 4.0. Which is much different then the limited version which shipped with IIS 3.0. The set of COM objects which consist of the FileSystemObject software are all free and cover almost every feature needed.
[Top]



Support the Active Server Industry