Solved

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

Posted on 2004-09-03
4
2,489 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 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