Results 1 to 10 of 10

Thread: Application.StartupPath Problem. [Resolved]

Threaded View

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Question Application.StartupPath Problem. [Resolved]

    Instead of setting a static path: "C:\Project\...\...\",
    I use "Application.StartupPath" to set the default path of the application dynamically during run-time.

    It works well all the while, but I encounter some problem in the situation below:

    I use an "OleDbConnection" to set a connection to Access database. And the connection string below is created:

    Provider=Microsoft.Jet.OLEDB.4.0;Password="";User ID=Admin;Data Source=D:\Albert\Visual Basic .NET\Address Book\bin\Database\Database.mdb;Mode=Share Deny None;Extended Properties="";Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet OLEDBatabase Password="";Jet OLEDB:Engine Type=5;Jet OLEDBatabase Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDBon't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False

    I try to change the Data Source of this OleDbConnection to refer to "Application.StartupPath & \Database\Database.mdb"
    because not every PC have this same path.

    This changes is done in the View Code mode under "Windows Form Designer generated code" region.

    After changing, the "OleDbConnection" connection string is like below:

    Provider=Microsoft.Jet.OLEDB.4.0;Password="";User ID=Admin;Data Source=" & Application.StartupPath "\Database\Database.mdb;Mode=Share Deny None;Extended Properties="";Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet OLEDBatabase Password="";Jet OLEDB:Engine Type=5;Jet OLEDBatabase Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDBon't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False

    When I run the program, the error occurs showing that the database cannot be found.

    When I debugged it deeper, I found that the Data Source is not refer to "Application.StartupPath\Database\Database.mdb"

    It actually refer to "C:\Program Files\Microsoft Visual Studio .NET\Common7\IDE\Database\Database.mdb"

    Why is this so? How can I solve this problem?

    Please guide. Thank you!
    Last edited by albertlse; Aug 21st, 2003 at 08:34 PM.

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