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

Michael Van Canneyt michael at freepascal.org
Tue Jan 25 20:01:31 CET 2011



On Tue, 25 Jan 2011, Bo Berglund wrote:

> On Mon, 24 Jan 2011 23:29:41 +0100, Bo Berglund
> <bo.berglund at gmail.com> wrote:
>
>>>
>>>> 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.
>>
> works fine with SELECT
>>
>>> 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)
>>
> I now repeated the same simple application code in Delphi7 where I
> used a TADOConnection and a TADOQuery component to execute the
> queries.
> I used the same ODBC datasource as had been used by the lazarus
> program and this time all 4 records were correctly retrieved.
>
>>
>>
>>> 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.
>>>
>
> No need since the ODBC connection is OK proven by the Delphi program.
> Now only remains to check why the sqldb component does not see all
> returned records when the verb is EXEC. It does see them if the asq is
> a select statemant exactly the same as the stored procedure
> executes...

... And that means you must debug the SQLDB component.

Please recompile and reinstall SQLDB with the instructions given earlier, give an additional option to make:

OPT=-gl

This will enable debug information for the SQLDB units.

After that, you can debug the ODBCConnection components.

The interesting routines where you should put a breakpoint are in odbcconn.pas :

line 690 : TODBCConnection.Fetch
line 648 : TODBCConnection.Execute
line 563 : TODBCConnection.PrepareStatement

Try to determine what they do differently when doing an EXEC and a SELECT.

Unfortunately I can't do it for you, since I have no MS-SQL database.

Michael.




More information about the Lazarus mailing list