Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Connection String

Connection String

Scheduled Pinned Locked Moved Visual Basic
helpdatabase
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jds1207
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • J 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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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 by Application.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

      J 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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 by Application.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

        J Offline
        J Offline
        jds1207
        wrote on last edited by
        #3

        Thanks, that worked great! jds1207

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups