Y
ywan
Unregistered / Unconfirmed
GUEST, unregistred user!
各位好,我用VB 建立一线程,线程里包括对数据库的一些操作,但在建立ADOCONNECTION对象时出现 automation error coinitialize has not been
called ,但VB好象不能调用 coinitialize(NULL),请教各位高手该如何处理?
数据库操作的类模块代码如下:
called ,但VB好象不能调用 coinitialize(NULL),请教各位高手该如何处理?
数据库操作的类模块代码如下:
代码:
Public ObjConn As ADODB.Connection
Public ObjRecordset As ADODB.Recordset
Public DataConnection As New ADODB.Connection
'连接数据库
Public Function openconnection() As ADODB.Connection
'On Error Resume Next
'Dim ObjConn As ADODB.Connection
On Error GoTo err1
If ObjConn Is Nothing then
Set ObjConn = New ADODB.Connection '出现错误
ObjConn.ConnectionString = "Provider=SQLOLEDB.1;Password=;
_
Persist Security Info=True;User _
ID=;Initial Catalog=SMS;Data _
Source=10.50.0.231"
ObjConn.Open
End If
Set openconnection = ObjConn
Exit Function
err1:
MsgBox "desc:" &
err.Description &
"help" &
err.HelpFile
End Function
'增加记录
Public Function InsertData(SqlSt As String) As Boolean
Dim InsertRS As New ADODB.Recordset
'On Error GoTo err
'Set InsertRS = New ADODB.Recordset
'If DataConnection.state = 0 then
Set DataConnection = openconnection
'End If
InsertRS.ActiveConnection = DataConnection
'InsertRS.DataSource = SqlSt
InsertRS.Open SqlSt, , , adLockOptimistic
InsertData = True
Set InsertRS = Nothing
Exit Function
'err:
'Set InsertRS = Nothing
'InsertData = False
End Function
'查询
Public Function QueryData(SqlSt As String) As ADODB.Recordset
On Error GoTo err
Set QueryData = New ADODB.Recordset
If DataConnection.state = 0 then
DataConnection = openconnection
End If
QueryData.ActiveConnection = DataConnection
QueryData.Source = SqlSt
QueryData.Open , , adOpenStatic, adLockReadOnly
Exit Function
err:
End Function