如何从.NET中的连接字符串获取.mdf
数据库的LocalDB
文件的文件路径?
示例字符串:
Data Source=(LocalDb)\v11.0;Initial Catalog=MyDb;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MyDb.mdf
答案 0 :(得分:1)
public static string GetFilePathFromConnectionString(string connectionString)
{
var attachDbFileName = new SqlConnectionStringBuilder(connectionString).AttachDBFilename;
return attachDbFileName.Replace("|DataDirectory|", AppDomain.CurrentDomain.GetData("DataDirectory").ToString());
}