Domanda

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" + "')");
È stato utile?

Soluzione

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" + "')");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top