几次比较稳定的结果
Marshal time 591
performance :
Marshal connect : 0
Marshal data to rs : 125
Marshal end : 0
0
Xml time 5618
performance :
xml connect : 0
xml open rs : 109
xml rs to xml : 2063
Xml end : 15
0
getstring time 1502
performance :
getStr connect: 0
getStr data to rs : 109
getStr rs to string: 235
getStr time: 0
0
Marshal time 591
performance :
Marshal connect : 0
Marshal data to rs : 109
Marshal end : 0
0
Xml time 5908
performance :
xml connect : 16
xml open rs : 109
xml rs to xml : 2063
Xml end : 0
0
getstring time 911
performance :
getStr connect: 0
getStr data to rs : 110
getStr rs to string: 234
getStr time: 0
0
Marshal time 591
performance :
Marshal connect : 0
Marshal data to rs : 125
Marshal end : 0
0
Xml time 6840
performance :
xml connect : 0
xml open rs : 110
xml rs to xml : 2062
Xml end : 0
0
getstring time 1572
performance :
getStr connect: 0
getStr data to rs : 125
getStr rs to string: 235
getStr time: 0
0
Marshal time 580
performance :
Marshal connect : 0
Marshal data to rs : 110
Marshal end : 0
0
Xml time 6009
performance :
xml connect : 15
xml open rs : 110
xml rs to xml : 2046
Xml end : 0
0
getstring time 901
performance :
getStr connect: 0
getStr data to rs : 110
getStr rs to string: 234
getStr time: 0
Private Declare Function GetTickCount Lib "kernel32" () As Long
Public Function MarGetData(ByRef ReturnRs As Recordset, ByRef PerformanceData As String) As Long
On Error GoTo errhandle
Dim ddd As Long
Dim ConnectStr As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim test As Long
ddd = GetTickCount
ConnectStr = ????
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.CursorLocation = adUseClient
cn.Open ConnectStr
PerformanceData = PerformanceData + "Marshal data to rs : " + CStr(GetTickCount - ddd) + Chr(13)
ddd = GetTickCount
Set ReturnRs = rs
'rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
MarGetData = 0
PerformanceData = PerformanceData + "Marshal end : " + CStr(GetTickCount - ddd)
Exit Function
errhandle:
MarGetData = -1
End Function
Public Function XmlGetData(ByRef XmlData As String, ByRef PerformanceData As String) As Long
On Error GoTo errhandle
Dim ddd As Long
Dim ConnectStr As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim oStream As ADODB.Stream
ddd = GetTickCount
ConnectStr = ????
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.CursorLocation = adUseClient
cn.Open ConnectStr
Set oStream = New ADODB.Stream
rs.Save oStream, adPersistXML
XmlData = oStream.ReadText
oStream.Close
Set oStream = Nothing
PerformanceData = PerformanceData + "xml rs to xml : " + CStr(GetTickCount - ddd) + Chr(13)
ddd = GetTickCount
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
XmlGetData = 0
PerformanceData = PerformanceData + "Xml end : " + CStr(GetTickCount - ddd)
Exit Function
errhandle:
XmlGetData = -1
End Function
Public Function StrGetData(ByRef StrData As String, ByRef PerformanceData As String) As Long
On Error GoTo errhandle
Dim ddd As Long
Dim ConnectStr As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
ddd = GetTickCount
ConnectStr = "Provider=SQLOLEDB.1;username=ying wenjing;password=ywj;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=WFMSTry;Data Source=m18dbhp"
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.CursorLocation = adUseClient
cn.Open ConnectStr
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
StrGetData = 0
PerformanceData = PerformanceData + "getStr time: " + CStr(GetTickCount - ddd)
Exit Function
errhandle:
StrGetData = -1
End Function
测试工程
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim rs As ADODB.Recordset
Dim stm As Stream
Dim str As String
Dim xmlreturn As String
Private Sub Command1_Click()
If rs.State = adStateOpen Then Debug.Print rs.GetString
End Sub
Private Sub Command2_Click()
Debug.Print xmlreturn
End Sub
Private Sub Command3_Click()
Debug.Print str
End Sub
Private Sub Command4_Click()
Dim aa As Object
Dim returnstr As String
Dim cc As Long
'Set rs = New Recordset
Set aa = CreateObject("ProDataTransfertest.CDataTransfertest")
cc = GetTickCount
Debug.Print aa.MarGetData(rs, returnstr)
Debug.Print "Marshal time " + CStr(GetTickCount - cc)
Debug.Print "performance :" + Chr(13) + returnstr
cc = GetTickCount
Debug.Print aa.XmlGetData(xmlreturn, returnstr)
Debug.Print "Xml time " + CStr(GetTickCount - cc)
Debug.Print "performance :" + Chr(13) + returnstr
For DCOM to work, the client must be able to reach the server by its actual IP
address. If you use firewalls that translate network addresses, the client
cannot use the actual IP address to reach the server. COM inserts the IP
address of the server computer into the interface marshaling packets that
are returned to the client. Instead of using the translated IP/header,
Remote Procedure Call (RPC, or DCOM) uses the actual IP address to reach
the server. Because the firewall prevents the client from directly accessing
the server, the client Does Not Work over Network Address Translation-Based Firewall .
但经过配置后就可以:
http://www.microsoft.com/com/wpaper/dcomfw.asp