You are not logged in.
Pages: 1
In a server (a VCL FOrms application), i use a THttpApiServer and in the Process function i load a DLL, call a function that must load data from a SQL Server 2008 database.
In a test program if i load my dll and call the function, all works, i see the data.
In the server, if i place a button, and in the onclick i load the dll, and clal the function, i see the data.
In the process function i always have an error, like the process function could not "see" SQL Server.
Maybe the Process funcion is executed in a separate thread wit low rights?
I connect to the server this way:
fProps := TOleDBMSSQLConnectionProperties.Create('WIN764\SQL2008','Test','sa','');
Debugging the SERVER (until now i debugged the CLIENT) i saw the error ... that was the ONLY table with ID as IDENTITY ...
Thank you for your help: without your question I would not debug the server, and I would not see the error.
I'm learning mORMot.
I have a SQL Server 2008 R2 Database, named "test", with some tables,
I'm building a REST Server and a REST Client.
Rest Client loads one by one some tables into ClientDataset linked to a DBGrid, i edit values and save back to the server and the database.
One of these tables gives me problems: i can update and delete exixting records (inserted in SQL Server management studio), but i can't insert new records from my REST client app.
In the table in the database i always have only the records i inserted by management studio.
This is the table structure in SQL Server:
CREATE TABLE [dbo].[Prodotti](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[Descrizione] [nvarchar](20) NULL,
[Prezzo] [float] NULL,
CONSTRAINT [PK_Prodotti] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
This is the data model:
TProdotto = class(TSQLRecord)
private
fDescrizione: RawUTF8;
fPrezzo: Double;
published
property Descrizione: RawUTF8 index 20 read fDescrizione write fDescrizione;
property Prezzo: Double read fPrezzo write fPrezzo;
end;
This is the update code:
procedure TFMClient.BtnApplyCDS(aCDS:TClientDataSet;aCls:TSQLRecordClass;aMemo:TMemo);
var
st : TUpdateStatus;
aRec : TProdotto;
aID : Integer;
Ok : Boolean;
begin
if aCDS.ChangeCount > 0 then
begin
aCDS.DisableControls;
aCDS.StatusFilter := [usModified, usInserted, usDeleted];
fModel := DataModel;
fClient := TSQLHttpClientWinHTTP.Create('localhost',SERVER_PORT,fModel);
try
while not aCDS.Eof do
begin
st := aCDS.UpdateStatus;
case st of
usModified : ...
end;
usInserted : begin
aID := -1;
aRec := aCls.Create(fClient,aID);
aRec.Descrizione = aCDS.FieldByName('Descrizione').AsString;
aRec.Prezzo := aCDS.FieldByName('Prezzo').AsFloat;
try
aID := fClient.Add(aRec,true);
finally
aRec.Free;
aMemo.Lines.Add('Insert ID '+IntToStr(aID)+', Res = '+BoolToStr(aID > 0,True));
end;
end;
usDeleted : ...
end;
end;
aCDS.Next;
end;
finally
aCDS.StatusFilter := [];
if Assigned(fClient) then
fClient.Free;
if Assigned(fModel) then
fModel.Free;
end;
end;
end;
This is an example of the sql sent by the REST server:
exec sp_executesql N'insert into dbo.Prodotti (ID,Descrizione,Prezzo) values (@P1,@P2,@P3)',N'@P1 bigint,@P2 nvarchar(4000),@P3 float',4,N'xxxx',45
go
Any idea?
Found a way ...
strJSON := fClient.RetrieveListJSON(TPerson,'ID > 0',[],'');
DSPerson.DataSet := JSONToClientDataSet(self, strJSON, fClient);
DSPerson.DataSet.Open;
I'm new to mORMot.
Starting from sample 28 i try to build a server and a client with data mapped on a SQL Server 2008 R2.
I must populate a TDBGrid on the client side with the records of a table on my DB.
I can load the records in a TSQLTableJson (i see TSQLTableJSON.RowCount is the correct number), but I can't fin a way to put these record in a standard TClientDataset for my TDBGrid.
Someone can help?
This is a part of my code
var
strJSON: RawUTF8;
tbJSON : TSQLTableJson;
fSQLDataset: TSynSQLTableDataSet;
begin
fModel := DataModel;
try
fClient := TSQLHttpClientWinHTTP.Create('localhost',SERVER_PORT,fModel);
try
tbJSON := fClient.ExecuteList([TPerson],'select * from person');
MemoPerson.Lines.Add('tbJSON.RowCount = '+IntToStr(tbJSON.RowCount));
//... here i need at least the conversion from TSQLTableJson to strJSON (RawUTF8), but i will appreciate other hints
//(simple hints! I'm totally new!)
//what I try to do:
DSPerson.DataSet := JSONToDataSet(nil, strJSON);
DSPerson.DataSet := JSONToClientDataSet(fSQLDataset, fJSON, fClient);
Pages: 1