Connection String
-
I am trying to make my connection string variable using application settings under Project properties. Here is my connection string when it is hard coded: Dim myConnString As String = "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" & Application.StartupPath & "\File.mdb" When I have it hard coded it works fine. But when I try to make it variable I keep getting the error: Format of the initialization string does not conform to specification starting at index 33. For the connection string value, I have the same code as posted above and I placed the following in the code: Dim myConnstring As String = My.Settings.ConnectionString ConnectionString is the name of the value in application settings. Can anyone help me with this connection string please. I know it may seem easy but I can't get it to work. jds1207
-
I am trying to make my connection string variable using application settings under Project properties. Here is my connection string when it is hard coded: Dim myConnString As String = "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" & Application.StartupPath & "\File.mdb" When I have it hard coded it works fine. But when I try to make it variable I keep getting the error: Format of the initialization string does not conform to specification starting at index 33. For the connection string value, I have the same code as posted above and I placed the following in the code: Dim myConnstring As String = My.Settings.ConnectionString ConnectionString is the name of the value in application settings. Can anyone help me with this connection string please. I know it may seem easy but I can't get it to work. jds1207
Putting
"Provider=Microsoft.Jet.OleDB.4.0;Data Source=" & Application.StartupPath & "\File.mdb"
in the settings won't work. You have to write some code to retrieve a complete string, like:
Provider=Microsoft.Jet.OleDB.4.0;Data Source={0}
from the config file, then replace the
{0}
with the value returned byApplication.StartupPath
.Public Shared Function GetConnectionString() As String
Dim configString As String = My.Settings.ConnectionString' Replace the {0} with the value from StartupPath. ' As a side, you can either pass in the filename of the database, or retrieve that ' from a setting in the config file also. Return String.Format(configString, Path.Combine(Application.StartupPath, "File.mdb"))
End Function
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Putting
"Provider=Microsoft.Jet.OleDB.4.0;Data Source=" & Application.StartupPath & "\File.mdb"
in the settings won't work. You have to write some code to retrieve a complete string, like:
Provider=Microsoft.Jet.OleDB.4.0;Data Source={0}
from the config file, then replace the
{0}
with the value returned byApplication.StartupPath
.Public Shared Function GetConnectionString() As String
Dim configString As String = My.Settings.ConnectionString' Replace the {0} with the value from StartupPath. ' As a side, you can either pass in the filename of the database, or retrieve that ' from a setting in the config file also. Return String.Format(configString, Path.Combine(Application.StartupPath, "File.mdb"))
End Function
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007