Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
want backup and restore database with this code


string cmd = @"BACKUP DATABASE [" + Application.StartupPath + @"\KANOON.MDF]<br />
                  TO  DISK = N'"+filename +"'";


but in same path such as Desktop con not get backup? please help me?
Posted
Comments
R. Giskard Reventlov 26-Jun-11 11:11am    
Are you trying to back up ot the same server or a dofferent one? Do you have the requisite permissions to do this?
jchoponis 26-Jun-11 23:18pm    
why backup to a .mdf? that's confusing. use a .bak extension for your file like int Abhinav's sol'n

1 solution

Picking up the example from here[^], you should be able to point to the exact location (path) in the TO DISK section of the statement.

SQL
USE AdventureWorks2008R2;
GO
BACKUP DATABASE AdventureWorks2008R2
TO DISK = 'Z:\SQLServerBackups\AdventureWorks2008R2.Bak'
   WITH FORMAT,
      MEDIANAME = 'Z_SQLServerBackups',
      NAME = 'Full Backup of AdventureWorks2008R2';
GO


Looks like either the path in filename is incorrect, or you may not have the appropriate permissions.
 
Share this answer
 

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