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

-
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
Question
All replies
-
-
-
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
- Edited by Cor Ligthert Sunday, April 16, 2017 8:56 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.- Proposed as answer by Cherry BuMicrosoft contingent staff, Moderator Tuesday, April 18, 2017 1:16 AM
-
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.