0
votes

I am brand new to programming, and I have been encountering several errors as I work to build an application. The additional information section of the Visual Studio error box delivers the following message:

An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll

Additional information: Format of the initialization string does not conform to specification starting at index 0.

This occurs as the application attempts to execute the following line of code:

    Dim da As New SqlDataAdapter(sql, cs)

I have been working to troubleshoot this to no avail. Thanks for any help you are kind enough to provide! Please find the additional info/code for the class below:

Imports System.Data
Imports System.Data.SqlClient


Public Class DButil
    Public cs As String

    Public Function GetDataView(ByVal sql As String) As DataView
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter(sql, cs)

        da.Fill(ds)

        Dim dv As New DataView(ds.Tables(0))
        Return dv
    End Function

    Public Sub New()

        cs = "Data Source=(LocalDB)\v11.0"
        cs += "Data Source=(LocalDB)'C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf';Integrated Security=True;"
        cs += "Integrated Security =True;Connect Timeout=30"
    End Sub

End Class

Thanks for the reply, Steve. That removed the error from the following line: Dim da As New SqlDataAdapter(sql, cs). An error now appears on the following line: da.Fill(ds). This error says SqlException unhandled, and that an expression of non-boolean type where a condition is expected near ",". Thoughts? –

2
at first glance your connection string doesn't look right. what type of database are you trying to connect to?Jeff
Thanks for the reply. It is a SQL database.ocsean
Need to see the content of the variable sql passed to the GetDataViewSteve

2 Answers

2
votes

Your connection string is really wrong.
For Sql Server 2012 with LocalDB instance you need

Public Sub New()
    cs =  "Server=(LocalDB)\v11.0;"
    cs += "Integrated Security=True;"
    cs += "AttachDbFileName=C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf;"
End Sub

See examples of connectionstrings for Sql Server at connectionstrings.com

1
votes

Your connection string is definitely wrong. Have a look at http://www.connectionstrings.com/sqlconnection/localdb-automatic-instance-with-specific-data-file/

Here is an example of how to query your database and return a dataview

Public Function GetDataView(sql As String) As DataView
Dim cs = "Server=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=C:\Users\Sean\Documents\Visual Studio 2013\Projects\349591\349591\cms.mdf;"

Using cnn As New SqlConnection(cs)
  Using cmd As New SqlCommand(sql, cnn)
    Try
      cnn.Open()
      Dim t As New DataTable
      t.Load(cmd.ExecuteReader)
      Return New DataView(t)
    Catch ex As Exception
      ''handle the error
    End Try
  End Using
End Using
End Function