[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2004-09-03
4
Medium Priority
?
2,518 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 1000 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 1000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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 was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

650 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