|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ExecuteReader errorI have 4 data source where I get my data from, and each data source is in its own thread. When receiving data, if it is a new commodity I am need to read from the database. Since I can receive data from different data source at the same time, it is possible that I read from the database at the same time. During ExecuteReader sometimes I will get the error "ExecuteReader requires an open and available Connection. The connection's current state is Open, Executing." How can I fix this ? This are my codes: Dim dr As OleDb.OleDbDataReader Dim cmd As New OleDb.OleDbCommand sql = "select [Open],[High],[Low],[Last] from CommodityPrice where Commodity = '" & sContract & "'" With cmd .Connection = g_ConnectionOLE .CommandText = sql Try dr = .ExecuteReader() Catch ex As Exception DBErr(bErr, bSuccess, ex, sCaller) If bSuccess Then cmd.Connection = g_ConnectionOLE dr = cmd.ExecuteReader() End If End Try End With fniles,
Each thread needs to open its own connection, select its data from the database, and then close the connection. Kerry Moorman Show quoteHide quote "fniles" wrote: > I am using OLEDBDataReader to read from an Access database. > > I have 4 data source where I get my data from, and each data source is in > its own thread. > > When receiving data, if it is a new commodity I am need to read from the > database. > > Since I can receive data from different data source at the same time, it is > possible that I read from the database at the same time. > > During ExecuteReader sometimes I will get the error > > "ExecuteReader requires an open and available Connection. The connection's > current state is Open, Executing." > > How can I fix this ? > > > > This are my codes: > > > > Dim dr As OleDb.OleDbDataReader > > Dim cmd As New OleDb.OleDbCommand > > > > sql = "select [Open],[High],[Low],[Last] from CommodityPrice where Commodity > = '" & sContract & "'" > > With cmd > > .Connection = g_ConnectionOLE > > .CommandText = sql > > Try > > dr = .ExecuteReader() > > Catch ex As Exception > > DBErr(bErr, bSuccess, ex, sCaller) > > If bSuccess Then > > cmd.Connection = g_ConnectionOLE > > dr = cmd.ExecuteReader() > > End If > > End Try > > End With > > > > > > |
|||||||||||||||||||||||