Article ID: 186342
Article Last Modified on 3/2/2005
Option Explicit
Public Function Database_Test_Method( _
ByVal szConnect As String) As String
On Error GoTo errhandler
Dim ctxObject As ObjectContext
Set ctxObject = GetObjectContext()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = New ADODB.Connection
With cn
.ConnectionTimeout = 10
.ConnectionString = szConnect
.Open
End With
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM Authors", cn, adOpenForwardOnly, _
adLockReadOnly
Database_Test_Method = "First value from database: " _
& rs(0).Value
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
ctxObject.SetComplete
Exit Function
errhandler:
ctxObject.SetAbort
Err.Raise vbObjectError, "MTSTest.Class1.Database_Test_Method", _
Err.Description
Exit Function
End Function
Public Function General_Test_Method() As String
On Error GoTo errhandler
Dim ctxObject As ObjectContext
Set ctxObject = GetObjectContext()
General_Test_Method = "String from General_Test_Method"
ctxObject.SetComplete
Exit Function
errhandler:
ctxObject.SetAbort
Err.Raise vbObjectError, "MTSTest.Class1.General_Test_Method", _
Err.Description
Exit Function
End Function
Private Sub Command1_Click()
Dim obj As Object
Set obj = CreateObject("MTSTest.Class1")
MsgBox obj.General_Test_Method
Set obj = Nothing
End Sub
Private Sub Command2_Click()
Dim szConnect As String
szConnect = "Driver={SQL Server};" & _
"Server=YourServerName;Uid=sa;Pwd=;Database=pubs"
'(NOTE: You may need to change the connection
' information to connect to your database.)
Dim obj As Object
Set obj = CreateObject("MTSTest.Class1")
MsgBox obj.Database_Test_Method(szConnect)
Set obj = Nothing
End Sub
Private Sub Form_Load()
Command1.Caption = "Call General_Test_Method"
Command2.Caption = "Call Database_Test_Method"
End Sub
161837 How To Create a DCOM Client/Server Application
177394 How To Troubleshoot Run-Time Error '429' in DCOM Applications
259719 How To Export a COM+ Application to Client Computers
266717 How To Create a DCOM Client/Server Application by Using VB
267836 How To Create a DCOM Client/Server with Events by Using Visual Basic
268550 How To Use Dcomcnfg for a Visual Basic DCOM Client/Server Application
269330 How To Troubleshoot DCOM for Visual Basic Client/Server Applications
Keywords: kbhowto kbdatabase kbdcom KB186342