Article ID: 196959
Article Last Modified on 3/14/2005
APPLIES TO
- Microsoft Visual Basic 5.0 Enterprise Edition
- Microsoft Visual Basic 6.0 Enterprise Edition
- Microsoft ActiveX Data Objects 2.0
This article was previously published under Q196959
SYMPTOMS
When you executing an ActiveX Data Objects (ADO) UpdateBatch on a disconnected recordset through Microsoft Transaction Server (remote) or Distributed Component Object Model (DCOM), the following error may occur:
If you are trying to assign a date value in a recordset with quotes around it, you get an 'Unspecified Error' only when attempting to do an UpdateBatch on the recordset remotely. This problem does not occur if the ADO component is running on the same computer as the client .exe.
RESOLUTION
There are two possible workarounds:
- Upgrade both the server and the client to Microsoft Data Access Objects 2.1 Service Pack 2 or later. The "Unspecified error" does not occur with a client and a server both using Microsoft Data Access Objects 2.1 Service Pack 2 or later.
- Put # signs around the date value when assigning to the resultset field. For example, rs.Value = #12/31/9999# instead of rs.Value = "12/31/9999."
STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.
This problem has been fix in Microsoft Data Access Objects 2.1 Service Pack 2.
MORE INFORMATION
Steps to Reproduce Behavior
The steps in this section encompass four sections:
- Creating the SQL Server table.
- Creating the Visual Basic ActiveX .dll.
- Creating the Visual Basic Standard EXE.
- Setting up Microsoft Transaction Server Explorer.
Creating the SQL Server Table
Start ISQL_w and execute the following script to create the test table for the ADO sample code. After executing the script you may close ISQL_w:
CREATE TABLE dbo.TestTable_SN ( col1 varchar (25) NOT NULL DEFAULT (user_name()), col2 datetime NOT NULL DEFAULT (getdate()) ) GO
Start Visual Basic and Create an ActiveX DLL Project
- From the Project menu, choose References and select the Microsoft Data Access Objects 2.0 Library and the Microsoft Data Access Objects Recordset 2.0 Library.
Paste the following code in the <Class> for the project:
Private strSQL As String Private strConnect As String Dim ADOCn As ADODB.Connection Public Function GetData() As ADOR.Recordset If Not ADOCn Is Nothing Then Else Err.Raise vbObjectError + 98, "ADOGetData", "No valid Connection" End If Dim ADORs As ADOR.Recordset Set ADORs = New ADOR.Recordset With ADORs .CursorLocation = adUseClient .ActiveConnection = ADOCn .CursorType = adOpenForwardOnly .LockType = adLockBatchOptimistic 'batch updates. .Open strSQL End With 'DisConnect the Recordset from the connection. Set ADORs.ActiveConnection = Nothing Set GetData = ADORs Set ADORs = Nothing End Function Private Property Get ConnectStr() As String ConnectStr = strConnect End Property Private Property Let ConnectStr(strCn As String) strConnect = strCn End Property Public Property Get SQL() As String SQL = strSQL End Property Public Property Let SQL(nSQL As String) strSQL = nSQL End Property Public Sub UpdateRS(ByVal ClientRs As ADOR.Recordset) Dim ADORs As New ADOR.Recordset If Not ADOCn Is Nothing Then Else Err.Raise vbObjectError + 99, "ADOUpdate", "No valid Connection" End If ADORs.ActiveConnection = strConnect ADORs.Open ClientRs ADORs.UpdateBatch End Sub Public Sub ADOConnect(strConnect As String, Optional CnTimeOut As _ Integer = 20) Set ADOCn = New ADODB.Connection With ADOCn .Provider = "MSDASQL" '"SQLOLEDB" .CursorLocation = adUseClient .ConnectionString = strConnect .CommandTimeout = CnTimeOut .Open End With ConnectStr = ADOCn End Sub
- Rename the Class to ADOData.
- Rename the Project to ADOProc.
- Compile the project and an ActiveX DLL named ADOProc.dll will be created and registered.
Creating a New Standard EXE Project to Call the DLL
- Open a new project and create a Standard EXE application.
- From the Project menu, choose References and select the Microsoft Data Access Objects 2.0 Library and the Microsoft Data Access Objects Recordset 2.0 Library and ADOProc.
- Add a Command button to the form.
- Add a text box to the form and change the name to txtValue.
Paste the following code into the General Declarations section of the form: NOTE: You may need to change the connect string to work in your environment.
Const strConnect = "Driver={SQL _ Server};Server=(local);Database=Pubs;Uid=Sa;Pwd=" Private Sub Command1_Click() On Error GoTo ErrorHandler Dim ADORs As ADOR.Recordset Dim objADOData As ADOProc.ADOData Dim rField As ADODB.Field Dim iValue As Byte ' Instantiate the Data Object. Set objADOData = New ADOProc.ADOData With objADOData .SQL = "SELECT * FROM TestTable_SN" .ADOConnect strConnect, 15 'Establish connection. End With Set ADORs = New ADOR.Recordset ' Rtrn the Resultset from Data object. Set ADORs = objADOData.GetData ' The Resultset is disConnected at this point. ADORs.AddNew ' Fails (Remotely - DCOM) if quotes around the ' Date value instead of pound sign. ADORs(0) = App.EXEName ADORs(1) = #12/12/98# ADORs.MarshalOptions = adMarshalModifiedOnly objADOData.UpdateRS ADORs MsgBox "Data Changed", vbOKOnly, "Data Object" Exit Sub ErrorHandler: MsgBox "Change Failed:" & vbCrLf & Err.Number & vbCrLf & _ Err.Description, vbOKOnly, "Data Object" Debug.Print Err.Number & vbCrLf & Err.Description Exit Sub End Sub
Setting up Microsoft Transaction Server Explorer
- Compile the Client application (the Standard EXE) and build a setup/install package with the Application Setup Wizard in Visual Basic 5.0 and the Package and Deployment Wizard for Visual Basic 6.0.
NOTE: For more information about using these, please refer to the Online help.
- Copy the install/setup program for the Client application to the remote computer and run the install.
- On the server, start Microsoft Transaction Server Explorer.
- Navigate to Microsoft Transaction Server, Computers, My Computer, Packages Installed.
- Right-click Packages Installed and select New Package.
- Create a new Empty Package, enter a name for the package, click Next twice, then click Finish.
- Navigate to your new package by name then navigate to the Component folder.
- Click Component then right-click Component. Select New-Component then choose "Import Components that are already Registered."
- Scroll down to the ADOProc.ADOData component and click Finish.
- Export the package to the second computer by right-clicking the Package folder (for your new package) and selecting Export.
- Browse to the computer to export the package and then name the exported package.
- On the client computer (where you exported the package), run the client Setup .exe to install/register the package on the remote client.
- When the Client application is installed run the application and you should not see any errors.
- Change the Client application to see the error by modifying the Visual Basic code as indicated in the source. That is, put quotes around the date value and recompile the Client application. Next, copy the client EXE file to the remote computer and rerun it. You should see an 'Unspecified Error' error message this time.
NOTE: The only difference in the code is the # signs around the date value.
REFERENCES
For additional information, please see the following article in the Microsoft Knowledge Base:
186342 HOWTO: Create a 3-Tier App using VB, MTS and SQL Server
Keywords: kbfix kbdatabase kbprb kbado210sp2fix KB196959