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

Marcos Douglas md at delfire.net
Thu Jan 20 12:58:14 CET 2011


On Wed, Jan 19, 2011 at 7:38 PM, Bo Berglund <bo.berglund at gmail.com> wrote:
> On Wed, 19 Jan 2011 19:27:58 +0100, Bo Berglund
> <bo.berglund at gmail.com> wrote:
>
>>Did this and indeed now I have the SQLdb tab on my lazarus.
>
> More problems:
> I have created a test application and did a cut-and-paste operation on
> the example on this page:
> http://wiki.lazarus.freepascal.org/Lazarus_Database_Tutorial#Lazarus_and_MSSQL
>
> After changing the specifics of the database (server, name, user,
> login) in the code I tried to run it in Lazarus debugger.
>
> After fixing the uses clause so it will compile and after creating a
> datasource pointing to my database I tried running against a real
> MSSQLServer database but it failed miserably with an exception on
> line:
>  query.Open;
>
> The exception text is:
> 'Cannot open a non-select statement'
>
> The database I run against uses stored procedures to select data and I
> have specified a call to such a procedure in the test program as
> follows:
>
> query.SQL.Text := 'EXEC SelectDongleData @SerialNo=2485';
>
> This works fine in my Delphi program where I use an ADO connection.
> There the query object is defined as
> qryADO: TADOQuery;
>
> and the code to get the records is:
>
>  sSql := 'EXEC SelectDongleData @SerialNo=' + IntToStr(KeyNo);
>  qryADO.SQL.Text := sSql;
>  qryADO.Open;
>
>
> What did I do wrong regarding the use of TSQLQuery to get this error?

Use query.ExecSQL instead of query.Open even in Delphi!

Marcos Douglas




More information about the Lazarus mailing list