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 8574683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:31:43+00:00 2026-06-11T19:31:43+00:00

Up till now I’ve been using the following connection string: public static String connectionString

  • 0

Up till now I’ve been using the following connection string:

public static String connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Ahmad\documents\visual studio 2010\Projects\DBtestApp1\DBtestApp1\TestDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

However, since the MDF file is in the same directory as the EXE running itself, and since this directory can change, I now was to retrieve the current directory using Directory.GetCurrentDirectory() ..

The problem is, a string assignment such as this does not work:

connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=\"" + currentDirectory + "TestDB.mdf\";Integrated Security=True;Connect Timeout=30;User Instance=True";

where currentDirectory holds the output of Directory.GetCurrentDirectory() ..

So whats the solution ?

  • 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-06-11T19:31:44+00:00Added an answer on June 11, 2026 at 7:31 pm

    This should actually work, but depending on the return value of Directory.GetCurrentDirectory() your path might be broken.

    Instead of concatenating the path within your string, you should use Path.Combine() provided inside System.IO for this, which will handle additional/missing backslashes between the parts to be concatenated:

    string DbFile = Path.Combine(Directory.GetCurrentDirectory(), "TestDB.mdf");
    

    You should then be able to simply add this string to your full connection string, which might be done using String.Format() as well:

    string connectionString = String.Format(@"...AttachDbFilename={0};Integrated...", Path.Combine(Directory.GetCurrentDirectory(), "TestDB.mdf"));
    

    I haven’t tried this, but shouldn’t it work using just .\TestDB.mdf as the filename? Or does it have to be an absolute path?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Till now I had been using following code to ftp file from one location
I have been using jQuery 1.23 till now and nowadays most of the plugins
Till now, I had been using Netbeans Swing GUI generation feature to build GUI
Till now, I have been using Netbeans IDE for Java Applications. To distribute applications
Till now, I have been using google charts and UIWebView to show graphs in
I have been using Micah Carrick's PAYPAL IPN class till now for web_accept but
Up till now we've been rewriting URL's using a custon 404 page: the url
till now i was using drawable to populate marker on my map .Now i
I have been a C++ / Linux Developer till now and I am adept
Till now I've been testing my web (usually written in PHP) as well as

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.