Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这可能很简单,但找不到从 sys.master_files 中选择 LDF 文件的示例。我已经使用了 MDF 文件
cmd.CommandText = ("select physical_name from sys.master_files where database_id = DB_ID('" + "mydatabasename" + "')");
您使用的查询实际上应该返回数据库的所有数据 (MDF) 和日志 (LDF) 文件。
但是,要仅返回日志文件,您只需在“类型”列上添加一个额外的条件。日志文件的类型为 1,因此:
cmd.CommandText = ("select physical_name from sys.master_files where type = 1 and database_id = DB_ID('" + "mydatabasename" + "')");