Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6140929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:10:52+00:00 2026-05-23T18:10:52+00:00

Given the following connection string (for SQL Server CE 4.0) Data Source=|DataDirectory|IntegrationTests.sdf how do

  • 0

Given the following connection string (for SQL Server CE 4.0)

Data Source=|DataDirectory|IntegrationTests.sdf

how do I figure out if the file exists?

(I know I can hard-code the path in a call to File.Exists(), but I don’t want to. What if I decide to change the connection string?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:10:52+00:00Added an answer on May 23, 2026 at 6:10 pm

    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);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following class structure is given: class Job { String description; Collection<JobHistory> history; } class
// given following array: $data = array( 0=>array( data=>object1, col=>array( 0=>array( data=>object2, col=>array( 0=>array(
Given the following URL: domain.com/page.aspx?id=123 How can I sanitize that query string value when
Can anyone please help me on the following: I have created a SQL Server
Given a group of files with the following naming convention: datetime_restofname.txt an example of
Given following Ruby statements: (Read input and store each word in array removing spaces
Given the following XML: <current> <login_name>jd</login_name> </current> <people> <person> <first>John</first> <last>Doe</last> <login_name>jd</login_name> </preson> <person>
Given the following: List<List<Option>> optionLists; what would be a quick way to determine the
Given the following example, why do I have to explicitly use the statement b->A::DoSomething()
Given the following: declare @a table ( pkid int, value int ) declare @b

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.