0

如何从.NET中的连接字符串获取数据库.mdf文件的文件路径?LocalDB

示例字符串:

Data Source=(LocalDb)\v11.0;Initial Catalog=MyDb;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MyDb.mdf
4

1 回答 1

1
public static string GetFilePathFromConnectionString(string connectionString)
{
    var attachDbFileName = new SqlConnectionStringBuilder(connectionString).AttachDBFilename;
    return attachDbFileName.Replace("|DataDirectory|", AppDomain.CurrentDomain.GetData("DataDirectory").ToString());
}
于 2013-05-03T12:30:02.337 回答