Microsoft KB Archive/196959

= PRB: 'Unspecified Error' Err Using ADO Data Marshalling w/ DCOM =

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:

Unspecified Error.

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:
 * 1) 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.
 * 2) 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.



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  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.</li> Rename the Project to ADOProc.</li> Compile the project and an ActiveX DLL named ADOProc.dll will be created and registered.</li></ol>

Creating a New Standard EXE Project to Call the DLL
 Open a new project and create a Standard EXE application.</li> 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.</li> Add a Command button to the form.</li> Add a text box to the form and change the name to txtValue.</li>  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

</li></ol>

Setting up Microsoft Transaction Server Explorer

 * 1) 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.
 * 1) Copy the install/setup program for the Client application to the remote computer and run the install.
 * 2) On the server, start Microsoft Transaction Server Explorer.
 * 3) Navigate to Microsoft Transaction Server, Computers, My Computer, Packages Installed.
 * 4) Right-click Packages Installed and select New Package.
 * 5) Create a new Empty Package, enter a name for the package, click Next twice, then click Finish.
 * 6) Navigate to your new package by name then navigate to the Component folder.
 * 7) Click Component then right-click Component. Select New-Component then choose "Import Components that are already Registered."
 * 8) Scroll down to the ADOProc.ADOData component and click Finish.
 * 9) Export the package to the second computer by right-clicking the Package folder (for your new package) and selecting Export.
 * 10) Browse to the computer to export the package and then name the exported package.
 * 11) On the client computer (where you exported the package), run the client Setup .exe to install/register the package on the remote client.
 * 12) When the Client application is installed run the application and you should not see any errors.
 * 13) 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.

<div class="references_section">