Solved

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

Posted on 2004-09-03
2
729 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
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…

773 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