i taking backups of sql server databases programmatically using c#. figured microsoft.sqlserver.management.smo , other libraries made purpose. can backup database. nice. here code :
var server = new server(@"" + instancename); var backuper = new backup(); try { backuper.action = backupactiontype.database; backuper.database = dbname; backuper.devices.adddevice(dbname + ".bak", devicetype.file); backuper.backupsetname = dbname + " - yedek"; backuper.backupsetdescription = "açık bulut depo - " + dbname + " - yedek"; backuper.expirationdate = datetime.now.addyears(20); server.connectioncontext.connect(); backuper.sqlbackup(server); } catch(exception ex){//..}
my question here how can path of device database backed into? know can specify own path :
backuper.devices.adddevice("c:\somepath\" + dbname + ".bak", devicetype.file);
then can know is, want default location , path. please me out this.
from blog post, use function below:
http://www.mssqltips.com/sqlservertip/1966/function-to-return-default-sql-server-backup-folder/
create function dbo.fn_sqlserverbackupdir() returns nvarchar(4000) begin declare @path nvarchar(4000) exec master.dbo.xp_instance_regread n'hkey_local_machine', n'software\microsoft\mssqlserver\mssqlserver',n'backupdirectory', @path output, 'no_output' return @path end;
Comments
Post a Comment