Hi,
can anybody suggest me how to take backup and restore of sqlexpress.
I have used sqlexpress in my project i have little bit idea about taking backup and restore of sql server using SMO but unaware about sqlexpress. Can anybody help me please....

Thanks in Advance

Recommended Answers

All 3 Replies

You just need to use the appropriate SQL command.
I use something like this:
Backup -
"USE MASTER; BACKUP DATABASE [<DBName>] TO DISK = N'<FileName>' WITH FORMAT, INIT, NAME = N'<Backup Name>', SKIP"
Restore -
"USE MASTER; RESTORE DATABASE [<DBName>] FROM DISK = N'<FileName>' WITH FILE = 1, REPLACE"

Execute using the SQLCommand.ExecuteNonQuery method.

Note: I run the command in a service to ensure full access.
Not sure if it will work from a standard user program (which is probably why I do it from a service.)

Hi nick.crane, Can you explain the query in little bit detail

what is "USE MASTER",
Thanks in advance

The USE command changes to reference database for other commands.
I found I needed this to "disconnect" my current connection from the DB I was backing up otherwise the BACKUP did not always work.
Some examples of the BACKUP command are found here: How to: Create a Full Database Backup (Transact-SQL)
Full spec. for the BACKUP found here: BACKUP (Transact-SQL) (This also has links to Restore examples at the bottom.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.