Movable connection string

JohnV

Active member
Joined
Feb 20, 2015
Messages
27
Programming Experience
3-5
Hi,

I would like my vb.net (MS Access) connection string to be movable and not in permanent place. basically I wanted to not specifying the whole path or address. I will use one work station as my main server and 5 user will access that application.

Here is my MS access connection string written in VB.net. By the way, i"m using MS Access 2013

conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\JOV\Desktop\FeedBackSystem\FBSystems\FBSystems\Data\KPI.accdb"


Thank you.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,148
Location
Sydney, Australia
Programming Experience
10+
Don't hard-code a connection string. Open the Settings page of the project properties and add a connection string there. You can then access it in code via My.Settings and edit in in the config file, which means it can be changed after deployment without recompiling.
 

JohnV

Active member
Joined
Feb 20, 2015
Messages
27
Programming Experience
3-5
Hi Jim, I would like to ask when i run my application the database that was access is stored in bin/x86/Debug folder . Why not this path below instead

C:\Users\JV\Desktop\FeedBackSystem\FBSystems\FBSystems\Data.


Below is the codes I used to connect.

Dim conn As New System.Data.OleDb.OleDbConnection()
 conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=|DataDirectory|\KPI.accdb"



 
Last edited:

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,148
Location
Sydney, Australia
Programming Experience
10+
For a Windows app that is not deployed using ClickOnce, the default location for the data directory is the folder containing the EXE. If you don't want that then you have to either change the data directory or else don't use "|DataDirectory|" in your connection string.
 
Top Bottom