且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过c#中的帐户SQL服务器获取服务器的目录

更新时间:2023-02-07 21:08:01

如果该服务器中已存在的任何数据库的任何备份,则可以获取文件路径通过以下查询:



从msdb.dbo.backupmediafamily中选择physical_device_name 





在这些路径中你可以获得任何一个并执行以下查询来创建数据库的备份:



  BACKUP   DATABASE   @ DBName  
TO DISK = @ Path
WITH FORMAT;

E>

dear All
I am doing a project winform by c# language. my application has a module is backup database into .bak and save in folder in same server.
But I don't know how to get directory of server by account SQL server.
it is display like when find file to attach to SQL server.

If any backup of any database already present in that server then you can get the file path by the following query:

select physical_device_name from msdb.dbo.backupmediafamily



among those paths you can get any one and execute following query to create backup of your database:

BACKUP DATABASE @DBName
TO DISK = @Path
   WITH FORMAT;