Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have written the code for the backups, but I got an error?
C#
SqlCommand cmd = new SqlCommand();
           cmd.Connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dbcn.mdf;Integrated Security=True;Connect Timeout=10;User Instance=True");
           cmd.Connection.Open();
           string dbname = cmd.Connection.Database;//'
           cmd.Connection.Close();
           string pateh="C:\\USERS\\BCMODIR\\DOCUMENTS\\";
           SqlConnection.ClearAllPools();
           string query = "BACKUP DATABASE [" + dbname + "] TO DISK ='"+ pateh+ "\\backup.bak'";
           cmd.Connection = new SqlConnection(@"Data Source=.\sqlexpress;Integrated Security=True;Connect Timeout=30;User Instance=True");
           cmd.Connection.Open();
           cmd.CommandText = query;
           cmd.ExecuteNonQuery();
           cmd.Connection.Close();
           MessageBox.Show("database backup: ok");



error:

C#
Invalid column name 'is_compressed'.
Invalid column name 'compressed_backup_size'.
Could not insert a backup or restore history/detail record in the msdb database. This may indicate a problem with the msdb database. The backup/restore operation was still successful.
Processed 184 pages for database 'C:\USERS\BCMODIR\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\FRMSABT\FRMSABT\BIN\DEBUG\DBCN.MDF', file 'dbcn' on file 3.
Processed 1 pages for database 'C:\USERS\BCMODIR\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\FRMSABT\FRMSABT\BIN\DEBUG\DBCN.MDF', file 'dbcn_log' on file 3.
BACKUP DATABASE successfully processed 185 pages in 0.271 seconds (5.333 MB/sec).
Posted
Comments
Sergey Alexandrovich Kryukov 14-Mar-13 18:12pm    
Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

1 solution

hi,
try this solution below
http://www.mssqltips.com/sqlservertip/1849/backup-and-restore-sql-server-databases-programmatically-with-smo/[^]
It shows how to take backup programmatically.
 
Share this answer
 
Comments
bcsilent 20-Oct-12 14:54pm    
Unfortunately, the training was not adequate

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900