Figure out if a SQL Server CE 4.0 database file exists based on connection string?

Perhaps use the SqlConnectionStringBuilder Class to parse your connection string into its component pieces.

Perhaps use the SqlConnectionStringBuilder Class to parse your connection string into its component pieces: class Program { static void Main() { // Create a new SqlConnectionStringBuilder and // initialize it with a few name/value pairs. SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(GetConnectionString()); // The input connection string used the // Server key, but the new connection string uses // the well-known Data Source key instead. Console.

WriteLine(builder. ConnectionString); // Pass the SqlConnectionStringBuilder an existing // connection string, and you can retrieve and // modify any of the elements. Builder.

ConnectionString = "server=(local);user id=ab;" + "password= a! Pass113;initial catalog=AdventureWorks"; // Now that the connection string has been parsed, // you can work with individual items. Console.

WriteLine(builder. Password); builder. Password = "new@1Password"; builder.

AsynchronousProcessing = true; // You can refer to connection keys using strings, // as well. When you use this technique (the default // Item property in Visual Basic, or the indexer in C#), // you can specify any synonym for the connection string key // name. Builder"Server" = "."; builder"Connect Timeout" = 1000; builder"Trusted_Connection" = true; Console.

WriteLine(builder. ConnectionString); Console. WriteLine("Press Enter to finish.

"); Console.ReadLine(); } private static string GetConnectionString() { // To avoid storing the connection string in your code, // you can retrieve it from a configuration file. Return "Server=(local);Integrated Security=SSPI;" + "Initial Catalog=AdventureWorks"; } } In this case you can use the DataSource property: SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder("Data Source=|DataDirectory|IntegrationTests. Sdf"); Console.

WriteLine(builder. DataSource).

Kragen" thx, was just looking for that! – Mitch Wheat Jul 15 at 8:56 Turns out I couldn't use SQL Server CE anyway, since nested transactions wasn't supported (and I'm not in control of the code that handles transactions)... but this would definitely have done the job =) – Tomas Lycken Jul 15 at 11:47.

It seems that for Sql Server Express edition, the use of |DataDirectory| automatically triggered the check for file existence and even its creation if it does not exist. Not sure if the same holds true for Sql Server CE. Here's the only (old) reference I could find: msdn.microsoft.com/en-us/library/aa47894... If you want to resolve |DataDirectory| to your actual path and do the checking by yourself, however, you could use: AppDomain.CurrentDomain.

GetData(“DataDirectory�).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions