Im migrating a DA Delphi server to Oxygene .net console server.
Theres any sample (not using Winforms) for that?
I need to undesrtand how to create a Connection, schema, driver manager and load .schema , .connection files at runtime.
Also need to understand how to migrate that code (running at the server side) in a Oxygene dot net server.
var
lConnection : IDAConnection;
lQuery : IDADataset;
dw : TDAWhereBuilder;
begin
try
lConnection := ServerDataModule.ConnectionManager.NewConnection(fDBConexion);
if not lConnection.InTransaction then lConnection.BeginTransaction;
lQuery := SchemaGetDataset(lConnection, ServerDataModule.Schema, 'TABLA');
dw := lQuery.DynamicWhere;
dw.Expression := dw.NewBinaryExpression('', 'IDTABLA', dboEqual, 100);
lQuery.Active := True;
result := lQuery.FieldByName('NAME').AsString;
if lConnection.InTransaction then lConnection.CommitTransaction;
except
on e:exception do
begin
if lConnection.InTransaction then lConnection.RollbackTransaction;
end;
end;
end;
Which drivers can use to MS SQL server and Postgres server on dot net schema?
For PostgreSQL - NPGSQL.NET. Please note that for this driver you’ll have to deploy additional files with your server app (can be found in “…\RemObjects Software\Data Abstract for .NET\Bin\Npgsql” ) - Npgsql.dll and Mono.Security.dll on Windows and Npgsql.dll only on Mac / Linux
Both places. To access local data in the server I use that approach and in a Service Method also, to fill an array an return, be example. Why is important where it run? You make my doubt if I understand your question. Is not only relevant it run at server side?
Well, the code by itself looks very old-fashioned - it doesn’t use some of the newer DA concepts like LocalDataAdapter instead of manual connection management.
The difference is that:
If it is run from within any service method then we can use currently existing service to instantiate our very own DataService instance to access data via it and not worry about connections, schemas etc
If it is run from a DataService method where we already have a connection and a Schema - we can use another approach to access data
It is possible to use approach like the one in your code. but it would bypass any data access logging and validation.
If for use in that approach need another interface or component names can please just translate that little sample code to DA for net library? I have a lot of code using that way and need working ASAP.
After that will analyze and migrate to the approach you explain before.
It loads a Schema named “WinFormsApplication12Dataset”
Composes a DynamicWhere condition (Field named Id should be equal to 1105)
Opens a connection named “PCTrade-SQLite”
Opens data reader on the Schema table named Orders with DynamicWhere condition applied. Note that it only reads fields Id and OrderDate
Reads data
Disposes DB command, closes connection and releases it back to the pool
I used different table and field name to test this code on our sample database to be 100% sure that it works
.
method Test(): DateTime;
begin
var serviceSchema := RemObjects.DataAbstract.Server.SchemaAccess.RetrieveCachedSchema("WinFormsApplication12Dataset");
var whereCondition := new RemObjects.DataAbstract.Expressions.BinaryExpression(new RemObjects.DataAbstract.Expressions.FieldExpression("Id"), 1105, RemObjects.DataAbstract.Expressions.BinaryOperator.Equal);
var connection := RemObjects.DataAbstract.Server.Engine.ConnectionManager.AcquireConnection("PCTrade-SQLite", false);
try
connection.Open();
var columnMappings: RemObjects.DataAbstract.Schema.SchemaColumnMappingCollection;
var command: System.Data.IDbCommand;
try
using reader := serviceSchema.GetDataReader(connection, "Orders", [ "Id", "OrderDate" ], whereCondition.ToXmlNode(), nil, nil, out columnMappings, out command) do begin
reader.Read();
exit reader["OrderDate"] as DateTime;
end;
finally
command:Dispose();
end;
finally
connection.Close();
RemObjects.DataAbstract.Server.Engine.ConnectionManager.ReleaseConnection(connection);
end;
end;