用ADO编程,一个数据库连接,是否只能同时供一个线程使用?

我编写的程序中,多个线程同时使用一个数据库连接,会出现连接占线的错误.谁知道原因?
---------------------------------------------------------------

Nonnections aren't shared between processes. Each application uses its own connection resources. However, connections are shared between threads in multi-threaded applications.

I guess the problem you should use connection pooling .In my test i find if one connection have 5 session ,the client user will feel very slowly,so you can try use ado new version 2.6 or use OLEDB procider instead of ODBC provider connection.

pls see below:
Dim cn As Connection
Private Sub Form_Load()
Set cn = New Connection
cn.Open "Pubs"
End Sub
Private Sub cmdDoSomething_Click()
Dim rs As New Recordset
Dim dTime As Double
rs.Open "select * from Authors", cn
dTime = Timer
Do Loop Until Timer - dTime > 8
rs.Close
End Sub

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus