954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Procedure Holding Connection String

Hi! I have a vb.net project on a jump drive that connects to an Access (2003) database (located on the jump drive). My problem is when I change computers, I have to change the drive letter the jump drive is located. Currently, I have the following code and have to comment out the connection to the letter drives I do not need to use.

' Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=E:\Grad Project\Project.mdb;")
        ' Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=F:\Grad Project\Project.mdb;")
        'Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=N:\Grad Project\Project.mdb;")


I have been told I can create a procedure so that I only have to change the letter drive in one place and then each time I need to connect to the database, I can call that procedure.

Any idea how I would do this/code this?

Thanks!

rhonda2010
Newbie Poster
3 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

Store connection string in app.config or Put your databases inside the folder where your executable is and use |DataDirectory|.

Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|\Project.mdb;")
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: