Backing up inbuilt database in Visual Studio using c#

pacman99

New Member
I am developing a windows application using c# and inbuilt SQL Server on Visual Studio 2010. I am trying to create a click event to backup database to a specified location, but when I am running it, it is showing me error that database with this name doesn't exist.the code I am using is\[code\]try{ cnn.Open(); SqlCommand cmd = new SqlCommand("backupdb", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery(); MessageBox.Show("Backup completed successfully"); cnn.Close(); cnn.Open(); SqlCommand command; command = new SqlCommand(@"backup database [GRTU_LIBRARY_MANAGEMENT] to disk ='D:\test.bak' with init,stats=10", cnn); command.ExecuteNonQuery(); cnn.Close(); MessageBox.Show("The support of the database was successfully performed", "Back", MessageBoxButtons.OK, MessageBoxIcon.Information);}catch (Exception ex){ MessageBox.Show(ex.ToString());}\[/code\]Connection String is\[code\]<connectionStrings> <add name="GRTU_LIBRARY_MANGEMENT.Properties.Settings.GRTU_LIBRARY_MANAGEMENTConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\GRTU_LIBRARY_MANAGEMENT.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" /></connectionStrings>\[/code\]
 
Back
Top