Search code examples
sql-serversql-server-2008vb6

Procedure is not returning any data when run from VB6


I have a procedure in SQL Server that returns data. I use this in VB6, but in SQL returns data but in VB6 it doesn't, I lose the data.

ALTER PROCEDURE [dbo].[SP_L_UIF_Novedades] @bigint_dni bigint
AS BEGIN

    SET NOCOUNT ON

    SELECT UIFN.FechaNovedad,
           UIFA.DetalleDescripcion,
           CASE WHEN UIFN.Estado = 1 THEN 'SÍ' ELSE 'NO' END AS Estado,
           ISNULL(UIFN.ObservacionesVerificacion, '') AS ObservacionesVerificacion,
           ISNULL(UIFN.FechaVerificado, '') AS FechaVerificado,
           UIFN.id
    FROM UIFnovedades UIFN
         INNER JOIN Cliente C ON UIFN.IdCliente = C.Id
         INNER JOIN UIFalertas UIFA ON UIFN.IdAlerta = UIFA.Id
    WHERE C.andnicli = @bigint_dni
    ORDER BY UIFN.FechaNovedad DESC

END

When I execute this SP, SQL shows:

FechaNovedad DetalleDescripcion Estado ObservacionesVerificacion FechaVerificado id
45622.5236111111 Títulos "recomercializados" que por sumatoria de cuotas ( por el DNI ) estén finalizados sus planes Se recibio carta finalizacion. 28/11/24 45624 192431
45544.4298611111 Titulares que se obliguen a pagar en concepto de cuotas más de $ 10.000.- --- --/--/---- 175298

Data exists. This is my screen on vb6:

Option Explicit
Dim RsSuscriptorDetalle As Recordset 'cambio nombre rs para primer grilla
Dim RsSuscriptorDetalleDetalleNovedad As Recordset 'creado nuevo rs para segunda grilla

Private Sub Form_Load()

    Set RsSuscriptorDetalle = New Recordset
    RsSuscriptorDetalle.CursorLocation = adUseServer
    '....................................
    Set RsSuscriptorDetalleDetalleNovedad = New Recordset 'añadido hoy 16/01/2025
    RsSuscriptorDetalleDetalleNovedad.CursorLocation = adUseServer
    '....................................

    lblSuscriptor.Caption = FrmModSolNuevo.LblCic.Caption & " - " & FrmModSolNuevo.LblApellido.Caption & ", " & FrmModSolNuevo.LblNombre.Caption
    CargaGrillaEncabezado CLng(FrmModSolNuevo.LblCic.Caption)
End Sub

Private Sub CargaGrillaEncabezado(LngDni As Long)
DisenoGrillaUIFEncabezado

Fn_SP_L_UIF_Novedades LngDni, RsSuscriptorDetalle
    
    Dim i As Integer
    i = 1
    
    Do While RsSuscriptorDetalle.EOF = False
        FlexGrillaDatosUIFEncabezado.Rows = i + 1
        FlexGrillaDatosUIFEncabezado.TextMatrix(i, 0) = Format(RsSuscriptorDetalle!FechaNovedad, "dd/MM/yyyy")
        FlexGrillaDatosUIFEncabezado.TextMatrix(i, 1) = RsSuscriptorDetalle!DetalleDescripcion
        FlexGrillaDatosUIFEncabezado.TextMatrix(i, 2) = RsSuscriptorDetalle!Estado
        FlexGrillaDatosUIFEncabezado.TextMatrix(i, 3) = RsSuscriptorDetalle!Id
        
        Debug.Print "ObservacionesVerificacion desde recordset: " & RsSuscriptorDetalle!ObservacionesVerificacion
        Debug.Print "Longitud: " & Len(RsSuscriptorDetalle!ObservacionesVerificacion)

        FlexGrillaDatosUIFEncabezado.TextMatrix(i, 4) = RsSuscriptorDetalle!ObservacionesVerificacion
        FlexGrillaDatosUIFEncabezado.TextMatrix(i, 5) = IIf(IsNull(RsSuscriptorDetalle!FechaVerificado), "", Format(RsSuscriptorDetalle!FechaVerificado, "dd/MM/yyyy"))
        i = i + 1
        
        Debug.Print "ObservacionesVerificacion: " & RsSuscriptorDetalle!ObservacionesVerificacion
        Debug.Print "Len: " & Len(RsSuscriptorDetalle!ObservacionesVerificacion)
        Debug.Print "LenB: " & LenB(RsSuscriptorDetalle!ObservacionesVerificacion)
        Debug.Print RsSuscriptorDetalle.Fields("ObservacionesVerificacion").DefinedSize

        
        RsSuscriptorDetalle.MoveNext
    Loop
    'FlexGrillaDatosUIFEncabezado.Rows = FlexGrillaDatosUIFEncabezado.Rows - 1
    
    RsSuscriptorDetalle.Close
    Exit Sub
End Sub

Private Sub DisenoGrillaUIFEncabezado()
    Dim i As Integer
    
    FlexGrillaDatosUIFEncabezado.Clear
    FlexGrillaDatosUIFEncabezado.Cols = 6
    FlexGrillaDatosUIFEncabezado.Rows = 2
    FlexGrillaDatosUIFEncabezado.FixedRows = 1
    
    FlexGrillaDatosUIFEncabezado.TextMatrix(0, 0) = "Fecha"
    FlexGrillaDatosUIFEncabezado.ColWidth(0) = 1300
    FlexGrillaDatosUIFEncabezado.ColAlignment(0) = 4
    '-----------------------------------------------
    FlexGrillaDatosUIFEncabezado.TextMatrix(0, 1) = "Detalle de Alerta"
    FlexGrillaDatosUIFEncabezado.ColWidth(1) = 4000
    FlexGrillaDatosUIFEncabezado.ColAlignment(1) = 0
    '-----------------------------------------------
    FlexGrillaDatosUIFEncabezado.TextMatrix(0, 2) = "Archivado"
    FlexGrillaDatosUIFEncabezado.ColWidth(2) = 1400
    FlexGrillaDatosUIFEncabezado.ColAlignment(2) = 4
    '-----------------------------------------------
    FlexGrillaDatosUIFEncabezado.TextMatrix(0, 3) = "IdNovedad"
    FlexGrillaDatosUIFEncabezado.ColWidth(3) = 0
    FlexGrillaDatosUIFEncabezado.ColAlignment(3) = 4
    '-----------------------------------------------
    FlexGrillaDatosUIFEncabezado.TextMatrix(0, 4) = "Info.Verificado"
    FlexGrillaDatosUIFEncabezado.ColWidth(4) = 4000
    FlexGrillaDatosUIFEncabezado.ColAlignment(4) = 0
    '-----------------------------------------------
    FlexGrillaDatosUIFEncabezado.TextMatrix(0, 5) = "F.Verificado"
    FlexGrillaDatosUIFEncabezado.ColWidth(5) = 1300
    FlexGrillaDatosUIFEncabezado.ColAlignment(5) = 4
    '-----------------------------------------------
    
    '------------------------CENTRO LAS COLUMNAS FIJAS---------------------
    For i = 0 To FlexGrillaDatosUIFEncabezado.Cols - 1
      FlexGrillaDatosUIFEncabezado.FixedAlignment(i) = 4
    Next i
End Sub

Private Function Fn_SP_L_UIF_Novedades(ByVal LngDni As Long, _
                                        ByRef RsSuscriptorDetalle As Recordset) As Boolean

    Dim objCmd As ADODB.Command
    Set objCmd = New ADODB.Command
    objCmd.ActiveConnection = Cn
    objCmd.CommandType = adCmdStoredProc
    objCmd.CommandText = "SP_L_UIF_Novedades"
    objCmd.Parameters("@bigint_dni") = LngDni
    Set RsSuscriptorDetalle = objCmd.Execute
    
    Set objCmd = Nothing

End Function

on this line: RsSubscriberDetail!ObservationsVerification

I lose the data. When I debug

FlexGrillaDatosUIFEncabezado.TextMatrix(i, 3) = RsSubscriberDetail!Id -> up to this line, I get information

when I go to the next line: RsSubscriberDetail!ObservationsVerification -> here it doesn't bring anything, it's just empty

can someone explain to me what's happening?

I have done debugging, I have printed the value anyway, I have tried changing aduseserver to aduseclient, I have tried with if, with iif, with isnull, but the value never arrives. With FechaVerificado the same thing happens, the value is simply lost. It never arrives. debug print:

Debug.Print "ObservacionesVerificacion: " & RsSuscriptorDetalle!ObservacionesVerificacion
ObservacionesVerificacion: 


Debug.Print "Len: " & Len(RsSuscriptorDetalle!ObservacionesVerificacion) 
Len: 0

Debug.Print "LenB: " & LenB(RsSuscriptorDetalle!ObservacionesVerificacion) 
LenB: 0

Debug.Print RsSuscriptorDetalle.Fields("ObservacionesVerificacion").DefinedSize
4000

Solution

  • From memory, VB6 (or ADO?) had issues with reading LOB columns like TEXT/NTEXT/MAX-varchars when you don't read the columns from the resultset in the same order as in your SELECT, or if you read the same column twice etc.

    In your code, the ID-column is read ahead of ObservationsVerification, which messes things up.

    So keep the same order of resultSet fetching as in SELECT and it should work