[Lazarus] Accessing MS SQLServer database from Lazarus/FPC?

Bo Berglund bo.berglund at gmail.com
Mon Jan 24 23:24:35 CET 2011


On Mon, 24 Jan 2011 22:20:38 +0100 (CET), Michael Van Canneyt
<michael at freepascal.org> wrote:

>> As an experiment I added a line as follows after the query.Open
>> statement:
>>      i := query.RecordCount;
>>
>> But this only affirms the fact that the recordset handled by the query
>> only contains a single record, i = 1.

>
>In general RecordCount cannot be trusted; 
>It can be updated as the TDataset fetches records.
>
>In each case: SQLDB relies on ODBC to connect to MS-SQL.
>
>From testing with MS-Access and MySQL I know that ODBC works fine with other 
>databases, at least for SELECT Statements.
>
>1. Can you test a regular SELECT statement on the same SQL database ?
>    If that doesn't work either, we know the problem is in the ODBC connection component.
>
>2. Can you test the same EXEC statement in a Delphi app through ODBC ?
>    If this gives problems, it means the ODBC driver is well - weird.
>    (although this would surprise me)
>
>3. If both previous attempts work, there is nothing left but to debug the ODBC connection component.
>    That means stepping through your code with the debugger.
>
>Michael.

I did this before too, but I have repeated it now by copying the
procedure code into the application. The procedure differentiates the
processing depending on the value of the argument, but I have copied
the relevant select section into the lazarus project code.

'SELECT dr.SerialNo, da.AppNo, da.AppOption, da.AppInfo, da.ExpDate,
da.ProgDate' +
' FROM DongleReg dr' +
' JOIN DongleAppData da' +
' ON da.DongleRegID = dr.DongleRegID' +
' WHERE dr.SerialNo = 2584' +
' ORDER BY da.AppNo ASC';

As expected it runs just fine returning 4 records, in fact the
query.RecordCount method actually shows this too. :-)

Only problem is that our database contains a whole lot of procedures
that return various kinds of data so I cannot really move that logic
over to the GUI application code. I really need to be able to retrieve
those records after sending an EXEC command (which now is legal in
sqldb.pp after the patch is applied).



-- 
Bo Berglund
Developer in Sweden





More information about the Lazarus mailing list