[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 737
  • Last Modified:

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

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
kwh3856
Asked:
kwh3856
1 Solution
 
gregasmCommented:
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
 
kwh3856Author Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now