Threading and Database connection problems

  • Thread starter Thread starter Cor Ligthert
  • Start date Start date
C

Cor Ligthert

Jerry,

In Net 1.x you can only use one connection in a time.

So when you want to use it as you do, you should create everytime a new
connection.

What is better anyway to get a more efficient connection.pooling (and than
use dispose in this case to close it everytime when your datareader process
is ready)

I hope this helps?

Cor
 
I have multiple threads in my application, each which open a connection to a
database as follows:

Sub ReaderThread()

Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
cmd.Connection = cn
cmd.CommandText = "SELECT * from Mytable"
dr = cmd.ExecuteReader

While dr.Read

'Do something

End While

cmd.dispose()
dr.close

do
'Do lots of things
loop

end sub


I am getting an error saying that "There is already a connection open" which
suggests that a connection on one thread is fighting with a connection on
the other.

Since I am declaring dr and cmd locally I can't work out why I am getting
this error.

-Jerry
 
Herfried,

When you want to show a thread about this than it is in my opinion better to
use a thread with Angel Saenz-Badillos[MS] in it.

Cor
 
Thank you all very much. Yes - I had the connection itself as a Public
variable. I have redefined it in each thread and it works fine.

Cheers

-Jerry
 

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

Back
Top