C# - Get file path from connection string

后端 未结 4 1797
隐瞒了意图╮
隐瞒了意图╮ 2021-01-13 22:10

Is there an existing method in C# to extract the file path from a string that represents a ConnectionString to a SqlCE .sdf file? I want t

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-13 22:21

    You could just create the connection and get the data source from it as a property:

    string data;
    using (var conn = new SqlConnection(connectionString)) {
        data = conn.DataSource;
    }
    

提交回复
热议问题