COM+组件连接数据库失败
我用vb 6.0写了一个测试COM+下远程传输Recordset对象的例子,组件的TestC返回long值,Test返回一个recordset对象。
虚拟机server 2003,本机是win7 64位操作系统。
我在虚拟机里面和win7系统下运行相同代码测试这两个方法,虚拟机里面能执行返回结果,win7下只能执行TestC方法,执行Test方法报用户sa不能登录。网上找了一下,也没有找到解决方法,求指教。
com+组件代码:
Option Explicit
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim count As Integer
Public Function Test() As ADODB.Recordset
Dim strconn As String
strconn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;pwd=sa;Initial Catalog=Northwind;Data Source=UFO-EBB345CC64C"
conn.ConnectionString = strconn
conn.CursorLocation = adUseClient
conn.Open
rst.ActiveConnection = conn
rst.Source = "select * from orders"
rst.Open
Set Test = rst
End Function
Public Function testC() As Long
count = count + 1
testC = count
End Function
Private Sub Class_Initialize()
count = 0
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset
End Sub
Private Sub Class_Terminate()
If rst.State = adStateOpen Then rst.Close
Set rst = Nothing
If conn.State = adStateOpen Then
conn.Close
End If
Set conn = Nothing
End Sub
远程客户端代码和本地的测试代码:
Option Explicit
Dim ts As proRemote.clsRemote
Private Sub Command1_Click()
Dim s As Integer
s = ts.testC
MsgBox CStr(s)
End Sub
Private Sub Command2_Click()
Dim ss As ADODB.Recordset
Set ss = ts.Test
MsgBox ss(2)
ss.Close
Set ss = Nothing
End Sub
Private Sub Form_Initialize()
Set ts = New proRemote.clsRemote
End Sub
Private Sub Form_Terminate()
Set ts = Nothing
End Sub
[解决办法]
最好在win7下调试,用ODBC应不会有问题