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 OLEDB
atabase 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 OLEDB
on'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 OLEDB
atabase 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 OLEDB
on'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!




atabase Password="";Jet OLEDB:Engine Type=5;Jet OLEDB
Reply With Quote