Results 1 to 8 of 8

Thread: [2008] "App.Path" in VB.net

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    70

    [2008] "App.Path" in VB.net

    Hi guys,

    I want my database path to be flexible, Im using App.Path in my code in VB6, how about in VB.net

    Thanks

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

    Re: [2008] "App.Path" in VB.net

    In your connection string you use |DataDirectory| for the folder, which will then be resolved to the appropriate location at run time. Note that you do NOT do this in code. It's part of the connection string, which you can create at design time or at run time. For instance, if you're using SQL Server Express your connection string may include "AttachDbFileName=|DataDirectory|\MyDatabase.mdf".

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    70

    Re: [2008] "App.Path" in VB.net

    Will it work even if i transfer my database and application in any folder??

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    70

    Re: [2008] "App.Path" in VB.net

    Code:
     con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & App.Path & "\TimeKeepingDB.accdb;Jet OLEDB:Database Password=tim3keeping23"
    How am i going to use the App.pAth version of VB.net in this connection string

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [2008] "App.Path" in VB.net

    [Edited by MartinLiss] I already answered your question. I said use |DataDirectory| for the folder and to not do it in code because it's part of your connection string. I even provided an example. How is that not clear? Let me spell it out for you:
    Code:
    con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\TimeKeepingDB.accdb;Jet OLEDB:Database Password=*************"
    As you seem to be having a little trouble the first time around, let me also say again that that will be resolved to the appropriate folder at run time.

    Thanks for providing your database password too, by the way.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: [2008] "App.Path" in VB.net

    Quote Originally Posted by M$Arrogance
    Well tell me why the vs ide loses the path to the database when you use it?
    Never happened to me or anyone that I know.
    Quote Originally Posted by M$Arrogance
    Why do ... M$ not have it documented any better than it is?
    How well do you need it documented?

    http://msdn.microsoft.com/en-us/library/ms254500.aspx
    http://www.connectionstrings.com/access
    http://www.connectionstrings.com/access-2007
    http://www.connectionstrings.com/sql-server-2005

  7. #7

  8. #8
    Addicted Member
    Join Date
    May 2008
    Location
    Denmark
    Posts
    178

    Re: [2008] "App.Path" in VB.net

    wierd he responded like that with his first post. Did you do a ip-check?

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