Solved

objConnection.Open() error.  Trying to write record to sql database and get error message

Posted on 2004-09-03
2
731 Views
Last Modified: 2012-08-13
I am trying to save a record to my sql 2000 database and get the following error message.

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

Additional information: System error.


Here is my code that creates the error message.

'Write ELA Objective Info record
            Dim objConnection As SqlConnection = New SqlConnection("server=(local);database=FBISK-TAKS;user id=sa;password=")
            Dim objCommand As SqlCommand = New SqlCommand
            objCommand.Connection = objConnection

            Dim r4 As Int16
            For r4 = 1 To 51
                objCommand.CommandText = "Insert Into itemAnalysisDetail " _
                            & "(admDate, studentId, teacherId, objectiveNumber, itemCorrectResp, studentResp) " & _
                            "VALUES(@admDate, @studentId, @teacherId, @readingElaobj(r4), @readingElaItemCorrectRespArray(r4), @readingElaStudentRespArray(r4))"
                objConnection.Open()      <<<<<--------------------------------RECEIVES the ERROR MESSAGE
                objCommand.ExecuteNonQuery()
                objConnection.Close()
            Next


Any help would be greatly appreciated.

Thanks
Kenny
0
Comment
Question by:kwh3856
2 Comments
 
LVL 8

Accepted Solution

by:
gregasm earned 500 total points
ID: 11973078
wrap the code in a try catch block and then view the message property. This way you may get some insight into the problem.

try

'Write ELA Objective Info record
            Dim objConnection As SqlConnection = New SqlConnection("server=(local);database=FBISK-TAKS;user id=sa;password=")
            Dim objCommand As SqlCommand = New SqlCommand
            objCommand.Connection = objConnection

            Dim r4 As Int16
            For r4 = 1 To 51
                objCommand.CommandText = "Insert Into itemAnalysisDetail " _
                            & "(admDate, studentId, teacherId, objectiveNumber, itemCorrectResp, studentResp) " & _
                            "VALUES(@admDate, @studentId, @teacherId, @readingElaobj(r4), @readingElaItemCorrectRespArray(r4), @readingElaStudentRespArray(r4))"
                objConnection.Open()      <<<<<--------------------------------RECEIVES the ERROR MESSAGE
                objCommand.ExecuteNonQuery()
                objConnection.Close()
            Next

catch ex as Exception
    msgbox(ex.message)


end try

What did the message say?
0
 

Author Comment

by:kwh3856
ID: 11973269
Greg,
I had the wrong password to login to SQL...

Thanks
Kenny


P.S.
I have a new error if you would like to try on that one.  I will post it as a new question.

Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

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