Redirecting strConnection

Gizmosays

Member
Joined
May 22, 2005
Messages
6
Programming Experience
Beginner
Hello I am fairly new at VB .net but I did manage to built myself a cool interface for a Movie database storing all the information in access using the following code to connect on form load.

Private ObjOleDbConnection As OleDbConnection
Private Connection As OleDbConnection
Private objOleDbCommand As OleDbCommand
Private objOleDbDataReader As OleDbDataReader
Const g_strConnectionstring As String = "Provider=Microsoft.jet.OLEDB.4.0;" & _
"Data source=\My Movie database\Database\Moviedatabase.mdb"

My problem is when I built my application setting it up with a installer the connection string will change base on where the user installs the program. Is there a way to go around this? Basically the database name will always be the same but the path will change depending on th users preference.

Thank you,
 
In VB.NET you need to use the Application object and its ExecutablePath property to get the path for the executable file that started the application, including the executable name:



VB.NET:
 Dim g_strConnectionstring As String = Application.ExecutablePath()

And, to get the path for the executable file that started the application, without the executable name use:


VB.NET:
 Dim aPath As String = Application.StartupPath()


in your case:

VB.NET:
Const g_strConnectionstring As String = "Provider=Microsoft.jet.OLEDB.4.0; " & _
"Data source=Application.StartupPath & "\Moviedatabase.mdb; Persist Security Info=False;"


Cheers ;)
 
Last edited:
Thank you for your quick response. I was trying to figure out how to apply the code in my application but I have failed. This is what I am assuming the application object does, it will only store a location of the the file that has called it. In my case the
Const g_strConnectionstring As String = "Provider=Microsoft.jet.OLEDB.4.0;" & _

"Data source=\My Movie database\Database\Moviedatabase.mdb"

is what calls the database to load in the list box but after packaging the application and using the windows installer to install in directory
C:\programfiles the connection string in my VB .net code is still referencing \My Movie database\Database\Moviedatabase.mdb so database will never load or will never be called and a database load failure occurs. I do not have a option for user to specify the location of the database I was hoping that I could automatically assign the connection string based on the location it was installed.
Hope this is not to confusing
 
Kulrom please excuse my ignorance you were right I completely was lost until I realized what you were doing in the code. Again I did mention I was new right . lol

Thank you again
 
Back
Top