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!

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;")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.