Problems with 'ExecuteReader requires an open and available Connection Error'

Joined
Aug 10, 2011
Messages
1
Reaction score
0
I am doing a big project saving an retrieving a large number of records including Picture data.
I don't know what i'm doing wrong but I keep getting the error : 'ExecuteReader requires an open and available Connection. The connection current state is closed.
This is my code:

Dim connection As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\owner\Desktop\DeeperLife Church Ja Data Apps\DeeperLife_Databank.mdb;")
Dim SelectCommand As New System.Data.OleDb.OleDbCommand("Select MemberID,Notes,Photo,First_name,Last_name,Title,Email,DOB,Marital_Status,Occupation,Date_Entered,Church_Rank,Member_Status,Street,Town,Parish,Street_mailing,Town_mailing,Parish_mailing,Phone_Primary,Phone_Work,Phone_Ext,Phone_Secondary FROM Members_Datatable WHERE MemberID ='" + membernum.Text.ToString() + "'", connection)

Dim da As New OleDb.OleDbDataAdapter(SelectCommand)

Dim myReader1 As System.Data.OleDb.OleDbDataReader
Dim ds As New DataSet("Members_Datatable")
Dim recordCount As Integer
recordCount = DataSet21.Tables("Members_Datatable").Rows.Count
Try
connection.Open()
Dim PictureBox1 As New System.Windows.Forms.PictureBox()
myReader1 = OleDbSelectCommand1.ExecuteReader()
If myReader1.Read() Then

Dim pictureData As Byte() = DirectCast(SelectCommand.ExecuteScalar(), Byte())
Adapter1.SelectCommand.Parameters("MemberID").Value = membernum.Text
Adapter1.SelectCommand.Parameters("Notes").Value = (notes.Text)
Adapter1.SelectCommand.Parameters("Photo").Value = (PictureBox1.Image)
Adapter1.SelectCommand.Parameters("First_name").Value = (fname.Text)
Adapter1.SelectCommand.Parameters("Last_name").Value = (lname.Text)
Adapter1.SelectCommand.Parameters("Title").Value = (comboboxtitle.Text)
Adapter1.SelectCommand.Parameters("Email").Value = (email.Text)
Adapter1.SelectCommand.Parameters("DOB").Value = (dateofbirth.Text)
Adapter1.SelectCommand.Parameters("Marital_Status").Value = (marital.Text)
Adapter1.SelectCommand.Parameters("Occupation").Value = (career.Text)
Adapter1.SelectCommand.Parameters("Date_Entered").Value = (startdate.Text)
Adapter1.SelectCommand.Parameters("Church_Rank").Value = (rank.Text)
Adapter1.SelectCommand.Parameters("Member_Status").Value = (membastatus.Text)
Adapter1.SelectCommand.Parameters("Street").Value = (street1.Text)
Adapter1.SelectCommand.Parameters("Town").Value = (town1.Text)
Adapter1.SelectCommand.Parameters("Parish").Value = (parishcombo1.Text)
Adapter1.SelectCommand.Parameters("Street_mailing").Value = (street2.Text)
Adapter1.SelectCommand.Parameters("Town_mailing").Value = (town2.Text)
Adapter1.SelectCommand.Parameters("Parish_mailing").Value = (parishcombo2.Text)
Adapter1.SelectCommand.Parameters("Phone_Primary").Value = (phone1.Text)
Adapter1.SelectCommand.Parameters("Phone_Work").Value = (phonework.Text)
Adapter1.SelectCommand.Parameters("Phone_Ext").Value = (workext.Text)
Adapter1.SelectCommand.Parameters("Phone_Secondary").Value = (phone2.Text)
connection.Close()

Dim picture As Image = Nothing
'Dim stream As New IO.MemoryStream(pictureData)
'picture = Image.FromStream(stream)
Using stream As New IO.MemoryStream(pictureData)
Me.PictureBox1.Image = picture
Adapter1.Fill(DataSet21)
da.Fill(ds)
Me.PictureBox1.Image = picture
PictureBox1.Dock = DockStyle.Fill

End Using
End If



If recordCount = 0 Then
MsgBox("There is no such ID in the database") ' & ControlChars.CrLf)
End If

Catch ex As System.Exception
MessageBox.Show("There was a problem reading the database." & ControlChars.CrLf & ex.Message)
Finally
If connection.State = ConnectionState.Open Then connection.Close()
connection.Dispose() : connection = Nothing

End Try

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top