Solved

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

Posted on 2004-09-03
4
2,457 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks to both of you very much....this was driving me nuts since I am new to VB.  


Thanks
Kenny
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now