This might be simple but can not find example of selecting LDF file form sys.master_files. I have got the MDF file using

    cmd.CommandText = ("select physical_name from sys.master_files where database_id = DB_ID('" + "mydatabasename" + "')");
有帮助吗?

解决方案

The query you are using should actually return all data (MDF) and log (LDF) files for your database.

However, to return only log files, you simply add an extra criteria on the 'type' column. Log files have a type of 1, hence:

cmd.CommandText = ("select physical_name from sys.master_files where type = 1 and database_id = DB_ID('" + "mydatabasename" + "')");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top