I'd like to connect to SQL server 2005 and I have a problem.
I'm using Lazarus-0.9.25-fpc-2.2.3-win32.exe and
Lazarus-0.9.25-fpc-2.2.3-cross-arm-wince-win32.exe
For ODBC it works fine on PC.
This is my application code:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
DBGrids, db, sqldb, odbcconn;
type
{ TForm1 }
TForm1 = class(TForm)
Button2: TButton;
btnSQLConnect: TButton;
Button4: TButton;
btnODBCConnect: TButton;
Datasource1: TDatasource;
DBGrid1: TDBGrid;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure btnODBCConnectClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure btnSQLConnectClick(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ private declarations }
m_SQLConnection: TSQLConnection;
m_ODBCConnection: TODBCConnection;
m_SQLTransaction: TSQLTransaction;
m_SQLQuery: TSQLQuery;
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
end;
procedure TForm1.btnODBCConnectClick(Sender: TObject);
begin
Button4.Enabled:=false;
try
m_ODBCConnection := TODBCConnection.Create(nil);
m_SQLTransaction := TSQLTransaction.Create(nil);
m_SQLQuery:=TSQLQuery.Create(nil);
with m_SQLTransaction do
begin
Action := caNone;
DataBase := m_ODBCConnection;
Active := false;
end;
with m_ODBCConnection do
begin
KeepConnection:=false;
LoginPrompt:=false;
Driver := 'SQL Server';
DatabaseName:=Edit1.Text; //alias
UserName:=Edit2.Text;
Password:=Edit3.Text;
Transaction:=m_SQLTransaction;
Connected:=true;
end;
with m_SQLQuery do
begin
DataBase := m_ODBCConnection;
ParseSQL := false;
Transaction := m_SQLTransaction;
SQL.Clear;
SQL.Add('SELECT ID FROM Article');
Open;
end;
Datasource1.DataSet := m_SQLQuery;
Button4.Enabled:=true;
except
on E:Exception do
begin
ShowMessage(E.Message);
Exit;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.btnSQLConnectClick(Sender: TObject);
begin
Button4.Enabled:=false;
try
m_SQLConnection := TSQLConnection.Create(nil);
m_SQLTransaction := TSQLTransaction.Create(nil);
m_SQLQuery:=TSQLQuery.Create(nil);
with m_SQLTransaction do
begin
Action := caNone;
DataBase := m_SQLConnection;
Active := false;
end;
with m_SQLConnection do
begin
KeepConnection:=false;
LoginPrompt:=false;
HostName:='192.168.0.7\sqlexpress';
DatabaseName:=Edit1.Text;
UserName:=Edit2.Text;
Password:=Edit3.Text;
Transaction:=m_SQLTransaction;
Connected:=true;
end;
with m_SQLQuery do
begin
DataBase := m_SQLConnection;
ParseSQL := false;
Transaction := m_SQLTransaction;
SQL.Clear;
SQL.Add('SELECT ID FROM Article');
Open;
end;
Datasource1.DataSet := m_SQLQuery;
Button4.Enabled:=true;
except
on E:Exception do
begin
ShowMessage(E.Message);
Exit;
end;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
m_SQLQuery.Close;
m_SQLQuery.Open;
end;
initialization
{$I unit1.lrs}
end.
I don't want to use ODBC or ZeosLib because application must work on WinCE (it doesn't have ODBC and Zeos don't work).
Please help.