Solved

Format of the initialization string does not conform to specficiation starting at index 46

Posted on 2004-09-03
4
2,473 Views
Last Modified: 2008-01-09
I am trying to open an SQL database and write a record.  Here is the error message I am getting.

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 46.


Here is the code.

'Get Math Objective Info

            Dim m As Int32
            Dim midx As Integer = 1
            Dim mathObjNumbersArray(60) As String
            For m = 1 To 101 Step 2
                mathObjNumbersArray(midx) = Mid(mathObjNumbers, m, 2)
                midx += 1
            Next

            Dim m1 As Int32
            Dim midx2 As Integer = 1
            Dim mathItemCorrectRespArray(60) As String
            For m1 = 1 To 101 Step 2
                mathItemCorrectRespArray(midx2) = Mid(mathItemCorrectResp, m1, 1)
                midx2 += 1
            Next

            Dim m2 As Int32
            Dim midx3 As Integer = 1
            Dim mathStudentRespArray(60) As String
            For m2 = 1 To 101 Step 2
                mathStudentRespArray(midx3) = Mid(mathStudentResp, m2, 2)
                midx3 += 1
            Next
            Try
                'Write Math Objective Info record
                Dim objConnection2 As SqlConnection = New SqlConnection("server=(local);database=FBISK-TAKS;user id=sa;password=""")    
                Dim objCommand2 As SqlCommand = New SqlCommand
                objCommand2.Connection = objConnection2

                Dim m4 As Int32
                For m4 = 1 To 60
                    objCommand2.CommandText = "Insert Into itemAnalysisDetail " _
                                & "(admDate, studentId, teacherId, objectiveNumber, itemCorrectResp, studentResp) " & _
                                "VALUES(@admDate, @studentId, @teacherId, @mathobj(m4), @mathItemCorrectRespArray(m4), @mathStudentRespArray(m4))"
                    objConnection2.Open()
                    objCommand2.ExecuteNonQuery()
                    objConnection2.Close()
                Next

            Catch ex As Exception
                MsgBox(ex.Message)

            End Try



Any help is greatly appreciated..

Thanks
Kenny

0
Comment
Question by:kwh3856
  • 2
4 Comments
 

Author Comment

by:kwh3856
ID: 11973439
My for next loop was set to 101.  I tried changing it to 30 but I still have the same problem
0
 
LVL 37

Assisted Solution

by:gregoryyoung
gregoryyoung earned 250 total points
ID: 11974300
I believe it is complaining about your connection string

New SqlConnection("server=(local);database=FBISK-TAKS;user id=sa;password=""")

also why are you opening and closing the connection every time through the loop ?

you should probably chnage this code to ...

            Dim m As Int32
            Dim midx As Integer = 1
            Dim mathObjNumbersArray(60) As String
            For m = 1 To 101 Step 2
                mathObjNumbersArray(midx) = Mid(mathObjNumbers, m, 2)
                midx += 1
            Next

            Dim m1 As Int32
            Dim midx2 As Integer = 1
            Dim mathItemCorrectRespArray(60) As String
            For m1 = 1 To 101 Step 2
                mathItemCorrectRespArray(midx2) = Mid(mathItemCorrectResp, m1, 1)
                midx2 += 1
            Next

            Dim m2 As Int32
            Dim midx3 As Integer = 1
            Dim mathStudentRespArray(60) As String
            For m2 = 1 To 101 Step 2
                mathStudentRespArray(midx3) = Mid(mathStudentResp, m2, 2)
                midx3 += 1
            Next
            Try
                'Write Math Objective Info record
                Dim objConnection2 As SqlConnection = New SqlConnection("server=(local);database=FBISK-TAKS;user id=sa;password=""")    
                Dim objCommand2 As SqlCommand = New SqlCommand
                objCommand2.Connection = objConnection2
                Dim m4 As Int32
                try
                    objConnection2.Open()
                    For m4 = 1 To 60
                        objCommand2.CommandText = "Insert Into itemAnalysisDetail " _
                                    & "(admDate, studentId, teacherId, objectiveNumber, itemCorrectResp, studentResp) " & _
                                    "VALUES(@admDate, @studentId, @teacherId, @mathobj(m4), @mathItemCorrectRespArray(m4),   @mathStudentRespArray(m4))"
                        objCommand2.ExecuteNonQuery()
                    Next
                Catch Ex as Exception
                     throw Ex
                Finally
                    objConnection2.Close()
                end Try
                objConnection2.Close()
            Catch ex As Exception
                MsgBox(ex.Message)

            End Try

0
 
LVL 4

Accepted Solution

by:
Javert93 earned 250 total points
ID: 11974365
You are missing a second quotation mark in your connection string. Currentym VB will expand this connection string:

    "server=(local);database=FBISK-TAKS;user id=sa;password="""

to this:

    server=(local);database=FBISK-TAKS;user id=sa;password="

You need to add two more quotes to the string so that the line looks like this:

    Dim objConnection2 As SqlConnection = New SqlConnection("server=(local);database=FBISK-TAKS;user id=sa;password=""""")

And if you start counting characters (starting at 0), the "p" in the password parameter is your 46th character, i.e. the "index 46" the error message is referring to.
0
 

Author Comment

by:kwh3856
ID: 11974409
Thanks to both of you very much....this was driving me nuts since I am new to VB.  


Thanks
Kenny
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question