Delphi mORMot 无法建立连接,因为目标机器主动拒绝
Delphi mORMot No connection could be made because the target machine actively refused it
我测试了 mORMot 组件。
我编译了标准演示“28 - Simple RESTful ORM Server”
运行 它并得到一个错误。
代码:
var
aModel: TSQLModel;
aProps: TSQLDBConnectionProperties;
aRestServer: TSQLRestServerDB;
aHttpServer: TSQLHttpServer;
begin
// set logging abilities
SQLite3Log.Family.Level := LOG_VERBOSE;
//SQLite3Log.Family.EchoToConsole := LOG_VERBOSE;
SQLite3Log.Family.PerThreadLog := ptIdentifiedInOnFile;
// ODBC driver e.g. from http://ftp.postgresql.org/pub/odbc/versions/msi
aProps := TODBCConnectionProperties.Create('','Driver=PostgreSQL Unicode'+
{$ifdef CPU64}'(x64)'+{$endif}';Database=postgres;'+
'Server=127.0.0.1;Port=5433;UID=postgres;Pwd=postgres','','');
//readln;
try
// get the shared data model
aModel := DataModel;
// use PostgreSQL database for all tables
VirtualTableExternalRegisterAll(aModel,aProps);
try
// create the main mORMot server
aRestServer := TSQLRestServerDB.Create(aModel,':memory:',false); // authentication=false
try
// optionally execute all PostgreSQL requests in a single thread
aRestServer.AcquireExecutionMode[execORMGet] := amBackgroundORMSharedThread;
aRestServer.AcquireExecutionMode[execORMWrite] := amBackgroundORMSharedThread;
// create tables or fields if missing
aRestServer.CreateMissingTables;
// serve aRestServer data over HTTP
aHttpServer := TSQLHttpServer.Create(SERVER_PORT,[aRestServer],'+',useHttpApiRegisteringURI);
try
aHttpServer.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries
writeln('Background server is running.'#10);
write('Press [Enter] to close the server.');
readln;
finally
aHttpServer.Free;
end;
finally
aRestServer.Free;
end;
finally
aModel.Free;
end;
finally
aProps.Free;
end;
end.
错误
{"Message":"TODBCLib error: [08001] Could not connect to the server;\nNo connection could be made because the target machine actively refused it.\r\n [127.0.0.1:5433]
如何清除。
我刚刚使用 Delphi Seattle 10 和来自 http://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_09_03_0400.zip 的 ODBC 驱动程序对其进行了测试 - 没问题。
确保您的 PostgreSQL 服务器已定义为 运行 在与源预期相同的端口上。如果您使用默认端口号,请将 5433
值编辑为 5432
。
由于偏执,我尝试始终更改默认端口,这减少了网络扫描攻击(至少来自快速扫描)。我从不将端口 22 用于 ssh,也从不将 5432 用于 PostgreSQL。抱歉给您带来不便。
我测试了 mORMot 组件。 我编译了标准演示“28 - Simple RESTful ORM Server” 运行 它并得到一个错误。
代码:
var
aModel: TSQLModel;
aProps: TSQLDBConnectionProperties;
aRestServer: TSQLRestServerDB;
aHttpServer: TSQLHttpServer;
begin
// set logging abilities
SQLite3Log.Family.Level := LOG_VERBOSE;
//SQLite3Log.Family.EchoToConsole := LOG_VERBOSE;
SQLite3Log.Family.PerThreadLog := ptIdentifiedInOnFile;
// ODBC driver e.g. from http://ftp.postgresql.org/pub/odbc/versions/msi
aProps := TODBCConnectionProperties.Create('','Driver=PostgreSQL Unicode'+
{$ifdef CPU64}'(x64)'+{$endif}';Database=postgres;'+
'Server=127.0.0.1;Port=5433;UID=postgres;Pwd=postgres','','');
//readln;
try
// get the shared data model
aModel := DataModel;
// use PostgreSQL database for all tables
VirtualTableExternalRegisterAll(aModel,aProps);
try
// create the main mORMot server
aRestServer := TSQLRestServerDB.Create(aModel,':memory:',false); // authentication=false
try
// optionally execute all PostgreSQL requests in a single thread
aRestServer.AcquireExecutionMode[execORMGet] := amBackgroundORMSharedThread;
aRestServer.AcquireExecutionMode[execORMWrite] := amBackgroundORMSharedThread;
// create tables or fields if missing
aRestServer.CreateMissingTables;
// serve aRestServer data over HTTP
aHttpServer := TSQLHttpServer.Create(SERVER_PORT,[aRestServer],'+',useHttpApiRegisteringURI);
try
aHttpServer.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries
writeln('Background server is running.'#10);
write('Press [Enter] to close the server.');
readln;
finally
aHttpServer.Free;
end;
finally
aRestServer.Free;
end;
finally
aModel.Free;
end;
finally
aProps.Free;
end;
end.
错误
{"Message":"TODBCLib error: [08001] Could not connect to the server;\nNo connection could be made because the target machine actively refused it.\r\n [127.0.0.1:5433]
如何清除。
我刚刚使用 Delphi Seattle 10 和来自 http://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_09_03_0400.zip 的 ODBC 驱动程序对其进行了测试 - 没问题。
确保您的 PostgreSQL 服务器已定义为 运行 在与源预期相同的端口上。如果您使用默认端口号,请将 5433
值编辑为 5432
。
由于偏执,我尝试始终更改默认端口,这减少了网络扫描攻击(至少来自快速扫描)。我从不将端口 22 用于 ssh,也从不将 5432 用于 PostgreSQL。抱歉给您带来不便。