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

  • SEARCH
  • Home
  • 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 8052329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:31:02+00:00 2026-06-05T07:31:02+00:00

Possible Duplicate: SQL Express Connection string – Relative to application location I have a

  • 0

Possible Duplicate:
SQL Express Connection string – Relative to application location

I have a desktop application written in vb.net. The app uses an SQL Server express 2008 database (.mdf file).
Currently i have the connection string as absolute path like this:

Dim ObjConnection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Pantheo\Documents\Visual Studio 2010\Projects\Food Manager 2012(new)\Food Manager 2012\Food_CustomerDB.mdf;Integrated Security=True;User Instance=True")

At my pc it runs just great. If i build it though and get the .exe to run to a defferent pc it crashes because it cannot attach the database.

I have tried to make it relative using this connection string:

 Dim ObjConnection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Food_CustomerDB.mdf;Initial Catalog=Food_CustomerDB;Integrated Security=True;User Instance=True")

with no success. Can someone help me? I know there are a ton other answers for it, basically regarding C#, but i cannot implement them. Thanks in advance

  • 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-05T07:31:03+00:00Added an answer on June 5, 2026 at 7:31 am

    The DataDirectory value is just a string extracted from the AppDomain.CurrentDomain property list. In a WinForm application is not pre-defined but you could set it before opening your database.

    AppDomain.CurrentDomain.SetData("DataDirectory", @"C:\MyReadWriteFolder")
    

    then the connection string with AttachDbFilename=|DataDirectory|\Food_CustomerDB.mdf should works provided you put the database there (C:\MyReadWriteFolder).

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

Sidebar

Related Questions

Possible Duplicate: Split string in SQL I have seen a couple of questions related
Possible Duplicate: SQL Count records within a month using a unix timestamp I have
Possible Duplicate: SQL Server Database query help Hi, I have a problem that I
Possible Duplicate: LINQ to SQL: Return anonymous type? I have a standard LINQ to
Possible Duplicate: SQL Server: Only last entry in GROUP BY I have a table
Possible Duplicate: Does SQL Server 2005 have an equivalent to MySql’s ENUM data type?
Possible Duplicate: sql to pick apart a string of a persons name and output
Possible Duplicate: Parameterizing a SQL IN clause? Hi, I have a query looks like
Possible Duplicate: SQL query to find Missing sequence numbers I have a table which
Possible Duplicate: SQL Server and connection loss in the middle of a transaction I

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.