Results 1 to 4 of 4

Thread: Data source configuration wizard sets absolute path of the database

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Niagara Falls
    Posts
    14

    Data source configuration wizard sets absolute path of the database

    Hello,

    I am using VS2008 and access database.

    I keep my database from application data folder. When I try to run the program in a different computer, I see in the error message, absolute path of the database file even though I used relative path. When I search the path as a string in the entire solution I found it in three files:

    Settings.Designer.vb
    Settings.settings (xml code)
    app.config (xml code)

    Is there an easy way to solve this problem or should I edit the files manually?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Data source configuration wizard sets absolute path of the database

    If you want to specify the program folder in a connection string then you use |DataDirectory|. If you want to change a connection string after deployment then you change it in the config file.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Location
    Niagara Falls
    Posts
    14

    Re: Data source configuration wizard sets absolute path of the database

    This is how I define my connection string in the code.

    Code:
        Dim appDataFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
        'connection string
        Dim cnStr As String = "Driver={Microsoft Access Driver (*.mdb)};" & _
                      "DBQ=licence_manager_2003.mdb;" & _
                      "DefaultDir=" & appDataFolder & "\MyDataFolder;" & _
                      "Uid=Admin;Pwd=;"
    I also changed settings.designer

    Code:
            <Global.System.Configuration.ApplicationScopedSettingAttribute(), _
             Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
             Global.System.Configuration.SpecialSettingAttribute(Global.System.Configuration.SpecialSetting.ConnectionString), _
             Global.System.Configuration.DefaultSettingValueAttribute("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""|DataDirectory|\MyDataFolder" & _
                "\licence_manager_2003.mdb""")>
    I also set |DataDirectory| folder while the main form loads:

    Code:
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            AppDomain.CurrentDomain.SetData("DataDirectory", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))
    However it is pointing the debugging directory and I get "not a valid path" error.

    What is wrong here? I am a beginner, what is the proper way to do that? Could you please explain in detail?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Data source configuration wizard sets absolute path of the database

    There's no point setting the DataDirectory if you're not using |DataDirectory| in your connection string. This:
    Code:
        Dim cnStr As String = "Driver={Microsoft Access Driver (*.mdb)};" & _
                      "DBQ=licence_manager_2003.mdb;" & _
                      "DefaultDir=|DataDirectory|\MyDataFolder;" & _
                      "Uid=Admin;Pwd=;"
    Also, don't use ODBC unless you have to. For Access, use OLE DB.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width