Handler 属性示例 (VB)
重要
从 Windows 8 和 Windows Server 2012 开始,RDS 服务器组件不再包含在 Windows 操作系统中(有关详细信息,请参阅 Windows 8 和 Windows Server 2012 兼容性指南)。 RDS 客户端组件将在将来的 Windows 版本中删除。 避免在新开发工作中使用此功能,并计划修改当前使用此功能的应用程序。 使用 RDS 的应用程序应迁移到 WCF 数据服务。
此示例演示 RDS DataControl 对象 Handler 属性。 (有关更多详细信息,请参阅 DataFactory 自定义。
假设参数文件中的以下部分 Msdfmap.ini位于服务器上:
[connect AuthorDataBase]
Access=ReadWrite
Connect="DSN=Pubs"
[sql AuthorById]
SQL="SELECT * FROM Authors WHERE au_id = ?"
代码如下所示。 分配给 SQL 属性的命令将与 AuthorById 标识符匹配,并将检索作者 Michael O'Leary 的行。 DataControl 对象 Recordset 属性将仅作为编码便利分配给断开连接的 Recordset 对象。
'BeginHandlerVB
Public Sub Main()
On Error GoTo ErrorHandler
Dim dc As New DataControl
Dim rst As ADODB.Recordset
dc.Handler = "MSDFMAP.Handler"
dc.ExecuteOptions = 1
dc.FetchOptions = 1
dc.Server = "https://MyServer"
dc.Connect = "Data Source=AuthorDataBase"
dc.SQL = "AuthorById('267-41-2394')"
dc.Refresh 'Retrieve the record
Set rst = dc.Recordset 'Use another Recordset as a convenience
Debug.Print "Author is '" & rst!au_fname & " " & rst!au_lname & "'"
' clean up
If rst.State = adStateOpen Then rst.Close
Set rst = Nothing
Set dc = Nothing
Exit Sub
ErrorHandler:
' clean up
If Not rst Is Nothing Then
If rst.State = adStateOpen Then rst.Close
End If
Set rst = Nothing
Set dc = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
'EndHandlerVB