Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sqlexec from vfp fails
Message
 
 
To
19/05/2016 11:36:50
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01636625
Message ID:
01636628
Views:
49
From our code:
.write_log('Sending Sql to server ...', program(), '5')
              lnSeconds = seconds()
              lnRetVal  = sqlexec(.nSQLHandle, lcStack + lcBeginSetRowCount + tcSQLString + lcEndSetRowCount, tcCursor)
              lnTurnaround = seconds() - lnSeconds
              .write_log('Result returned. Elapsed seconds: ' + ltrim(transform(lnTurnaround, '99999.999')), program(), '5')

              if lnRetVal < 0
                 declare laSqlError[1]
                 lnNumErrors = aerror(laSqlError)   && retrieve the error(s)
                 for lni = 1 to lnNumErrors        && process each error
                     lcMsg = "Communication Link Failure - cannot communicate with the SQL Server from " + this.cServerName + ". " + ;
                             "lnRetVal: " + transform(lnRetVal) + ' ' + laSqlError[lnI, 2]
                     .write_log(trim(lcMsg) + '  SQL Statement: ' + lcSQLLogString, tcCallingProg, 'E')
                     if alltrim(laSqlError[lnI, 4]) = '08S01' and ! tcCallingProg == 'RETRY'
                        * Connection Link Failure!!! - close and re-open connection...
                        .write_log("Setting .lSqlConnError to .T.", program(), '5')
                        .lSQLConnError   = .t.
                        .cSQLConnMSG   = lcMsg
                     endif
                 endfor
>i changed:
>
>..
>             ( b.[Date] >= '<< DTOS(dt1)>>' and b.[Date] <= '<< DTOS(dt2)>>' )
>,,,,
>
>still returns -1
>how would I implement aerror? sqlexc in help does not mention aerror
>as I said I never handled sqlserver before
>
>Thnaks
>
>Peter
>
>
>>>I need to get some data out of SQLserver from my vfp9sp2 app
>>>i have never done this btw
>>>here is what i got from the sql guy:
>>>
>>>declare @StartDate datetime , @EndDate datetime
>>>set @StartDate = '4/1/2016' set @EndDate = '4/30/2016'
>>>
>>>select a.*
>>>from BAI.F_Transaction a
>>>join dbo.D_Date b on ( a.GroupAsOfDate = b.RowID )
>>>where  ( DTransactionID = 1018 )
>>>             and
>>>             ( b.[Date] >= @StartDate and b.[Date] <= @EndDate )
>>>order by a.GroupAsOfDate desc
>>>
>>>
>>>
>>>here is my vfp translation
>>>
>>>
>>>dt1 = DATE(2016,4,1)
>>>dt2	= GOMONTH(dt1,1)-1
>>>
>>>
>>>lcServer = [OTT-sqlprod]
>>>
>>>
>>>CONNSTR = [Driver={SQL Server};Server=]+lcServer+[;Trusted_connection=Yes;Database=cmdw;]
>>>
>>>lnHandle = SQLSTRINGCONNECT( CONNSTR )
>>>*** returns 1
>>>
>>>IF Handle < 1
>>>	STRTOFILE( "Unable TO CONNECT TO SQL" + CHR(13) + CONNSTR, 16 )
>>>	RETURN
>>>ENDIF
>>>
>>>
>>>TEXT TO lcCMD NOSHOW TEXTMERGE
>>>select a.*
>>>from BAI.F_Transaction a
>>>join dbo.D_Date b on ( a.GroupAsOfDate = b.RowID )
>>>where  ( DTransactionID = 1018 )
>>>             and
>>>             ( b.[Date] >= '<<dt1>>' and b.[Date] <= '<<dt2>>' )
>>>order by a.GroupAsOfDate desc
>>>ENDTEXT
>>>
>>>
>>>
>>>lnSuccess returns -1
>>>
>>>what am I doing wrong
>>
>>The aerror will tell you the error. You may also use DTOS for your dates before putting them into the string.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform