none
How to Fix Format of the initialization string does not conform to specification starting at index 0.

    Question

  •  How does one fix the Index at 0 Error for the connection String?

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim con As New OleDb.OleDbConnection
            Dim provider As String
            Dim datafile As String
            provider = "Microsoft.ACE.OLEDB.12.0"
            datafile = "H:\Music Session Database\Music Database.accdb"
            con.ConnectionString = provider & datafile
            con.Open()
            MsgBox("Database Open")
            con.Close()
            MsgBox("Database Closed")
        End Sub

    Sunday, April 16, 2017 8:23 PM

All replies

  • As you stated it,    con.ConnectionString = provider & ";" & datafile

    I did not check if that is the only problem.


    Success
    Cor

    Sunday, April 16, 2017 8:28 PM
  • Still having the same problem here.
    Sunday, April 16, 2017 8:36 PM
  • Yea, 

    Sometimes is replying more difficult than giving a good solution . 

    However, this is how I would do this. 

         con.ConnectionString = "provider = Microsoft.ACE.OLEDB.12.0; datasource = H:\Music Session Database\Music Database.accdb"
     

    Be aware that H: is not such a good solution and you should use a UnC path

    https://en.wikipedia.org/wiki/Path_(computing)#Uniform_Naming_Convention


    Success
    Cor



    Sunday, April 16, 2017 8:53 PM
  • Hi WyvernForg,

    Please note that ConnectionString may have some issue in your code,

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;
    Persist Security Info=False;

    About ConnectionString, please refer to:https://www.connectionstrings.com/access/

    I modify your code, please refer to:

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim str As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Database\Database1.accdb; Persist Security Info=False;"
            Using conn As New OleDbConnection(str)
                conn.Open()
                MessageBox.Show("OK")
                conn.Close()
                MessageBox.Show("Close")
            End Using
    
        End Sub

    Best Regards,

    Cherry Bu



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 17, 2017 2:38 AM
    Moderator
  • Hi WyverFrog,

    Please remember to close your thread by marking the helpful post, it is beneficial to the other communities who face the same issue.

    Thanks for your understanding.

    Best regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, April 19, 2017 8:54 AM
    Moderator