A SQL Server Compact connection string allows you to specify the database name in various ways:
But sometimes you need the full path to the database file based on a user defined connection string. This week’s code snippet allows you to do exactly that, and it is a little bit quirky, as it works around a bug in SQL Server Compact 4.0 SP1, that causes use of |DataDirectory| to not be resolved correctly using only the SqlCeConnectionStringBuilder.
public string PathFromConnectionString(string connectionString)
SqlCeConnectionStringBuilder sb = new SqlCeConnectionStringBuilder(GetFullConnectionString(connectionString));
public string GetFullConnectionString(string connectionString)
using (SqlCeReplication repl = new SqlCeReplication())
repl.SubscriberConnectionString = connectionString;
Notice that the code above only works with version 4.0, not 3.5