#1 2014-10-22 08:52:00

aruncs08
Member
Registered: 2014-10-13
Posts: 27

What could be the Server_Root and Server_Port for MSSQL in RESTModel?

Hi!

I am working with a basic application which is similar to the '28 - Simple RESTful ORM Server'. But instead of PostGRE, I am using MSSQL database.

My Question: In that sample under RESTModel unit, they have a constant value as SERVER_ROOT = 'root';  SERVER_PORT = '888'; in my case for MSSQL, what could be the values of these constants?

Thanks in advance.

Offline

#2 2014-10-22 09:31:17

ChinaPeng
Member
Registered: 2014-10-02
Posts: 15

Re: What could be the Server_Root and Server_Port for MSSQL in RESTModel?

SERVeR_ROOT SERVER_PORT is use for http://localhost:127.0.0.1: 888/root/... is not a database connection

you can use unit SynDBODBC and declare

var aProps:  TODBCConnectionProperties;
   aProps := TODBCConnectionProperties.Create('','Driver=SQL SERVER;Database=Nuoxin;'Server=127.0.0.1,8829;UID=sa;Pwd=1','','');
    VirtualTableExternalRegister(aModel, TUserInfo, aProps, 'TB_SYS_USER');

more info

  http://synopse.info/forum/viewtopic.php?id=1547

Offline

#3 2014-10-22 10:11:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: What could be the Server_Root and Server_Port for MSSQL in RESTModel?

Yes, SERVER_ROOT = 'root' and  SERVER_PORT = '888' are the settings for RESTful URI remote access, not for external DB.

You can also try TOleDBConnectionProperties as defined in SynOleDB.pas, which gives even better results for performance.

Offline

#4 2014-10-22 11:36:29

aruncs08
Member
Registered: 2014-10-13
Posts: 27

Re: What could be the Server_Root and Server_Port for MSSQL in RESTModel?

@ChinaPeng: Thanks for your reply. I have another question, but I don't know whether it's a stupid question.

Question: How could I access the MSSQL local database in localhost or 127.0.0.1?

I have enabled tcp protocol(port: 1433) in mssql server configurations and mssql server is running perfectly. But I don't know how to access it in a localhost or 127.0.0.1.

@Admin: Thanks and I am using TOleDBConnectionProperties as defined in SynOleDB.pas in my application. Can you also answer my above mentioned question if possible.

Thanks in advance.

Last edited by aruncs08 (2014-10-22 11:39:15)

Offline

#5 2014-10-22 11:46:59

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: What could be the Server_Root and Server_Port for MSSQL in RESTModel?

Please show your initialization code, of both your TSQLRestServer and your TOleDBConnectionProperties.

Offline

#6 2014-10-22 12:23:22

aruncs08
Member
Registered: 2014-10-13
Posts: 27

Re: What could be the Server_Root and Server_Port for MSSQL in RESTModel?

TSQLRestServer code:

  aModel := DataModel; //Here DataModel is my RESTModel function

  aRestServer: TSQLRestServerDB;
  aRestServer:= TSQLRestServerDB.Create(aModel,':memory:',false);

Above I have followed just like the sample 28.

TOleDBConnectionProperties code:
 
  aProps: TSQLDBConnectionProperties;
  aProps := TOleDBMSSQLConnectionProperties.Create('ComputerUserName\SQLEXPRESS','Test','username','password');

As I said earlier, I don't how to access localhost connection for MSSQL database, so I have used my local database ServerName: 'ComputerUserName\SQLEXPRESS' and my Database name: 'Test'.

Offline

#7 2014-10-22 13:37:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: What could be the Server_Root and Server_Port for MSSQL in RESTModel?

What about the following:

 TOleDBMSSQLConnectionProperties.Create('.\SQLEXPRESS','Test','username','password');

as with regular OleDB/ADO connection string?

Offline

#8 2014-10-22 14:17:35

aruncs08
Member
Registered: 2014-10-13
Posts: 27

Re: What could be the Server_Root and Server_Port for MSSQL in RESTModel?

Thanks for your reply. I have changed as you said, but now the problem with HttpSetServiceConfiguration.

Error: project raised exception class EHttpApiServer with message 'HttpSetServiceConfiguration failed: The parameter is incorrect (87)'.

The coding part is:
 
  aHttpServer: TSQLHttpServer;
  aHttpServer := TSQLHttpServer.Create(SERVER_PORT,[aRestServer],'+',useHttpApiRegisteringURI);

Here SERVER_PORT:= 888 and aRestServer:= TSQLRestServerDB.Create(aModel,':memory:',false);

Thanks in advance.

Offline

#9 2014-10-22 15:16:56

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: What could be the Server_Root and Server_Port for MSSQL in RESTModel?

If you register the URI (via useHttpApiRegisteringURI), you need to run the application once with administration rights.
Please take a look at the SAD 1.18 documentation pdf.

Offline

#10 2014-10-23 09:51:38

aruncs08
Member
Registered: 2014-10-13
Posts: 27

Re: What could be the Server_Root and Server_Port for MSSQL in RESTModel?

Thanks for your suggestion, with administration rights our application runs. But again, there is a problem with the URL.

Error: Class EWinHTTP with message 'winhttp.dll error 12005 (The URL is invalid)'

My Code, related to this error:

aClient := TSQLHttpClientWinHTTP.Create('.\SQLEXPRESS',SERVER_PORT,aModel); //Server is '.\SQLEXPRESS', Server_Port is 888 and aModel is a DataModel function from RESTModel.

aClient.Add(aObject,true); //aObject is the RESTModel object.

In the above code if I change the server to 'localhost' instead of '.\SQLEXPRESS', then I got an error 'A connection with the server could not be established'.

Any solutions for this issue?

Thanks in advance.

Offline

#11 2014-10-23 11:12:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: What could be the Server_Root and Server_Port for MSSQL in RESTModel?

Your still making a confusion between the REST server and the MSSQL server.

Your TSQLRestServer + TSQLHTTPServer instances create a REST server at localhost.
This has nothing to do with '.\SQLEXPRESS'.

The correct parameter is 'localhost' or '127.0.0.1'.
I guess there is something else wrong in your code.
Please check the samples (e.g. "28 - Simple RESTful ORM Server") and fix your code.

Offline

#12 2014-10-23 16:40:59

aruncs08
Member
Registered: 2014-10-13
Posts: 27

Re: What could be the Server_Root and Server_Port for MSSQL in RESTModel?

Sorry, I was confused between the REST Server and MSSQL Server in that part.

Actually, now I am following the Sample 28. But I got an error 'A connection with the server could not be established'.

Code where the program breaks:

While debugging, the program breaks in the mORMot unit which follows

function TSQLRestClientURI.EngineAdd(TableModelIndex: integer;
  const SentData: RawUTF8): integer;
var P: PUTF8Char;
    url, Head: RawUTF8;
begin
  result := 0;
  url := Model.URI[Model.Tables[TableModelIndex]];
  if URI(url,'POST',nil,@Head,@SentData).Lo<>HTML_CREATED then
    exit; // response must be '201 Created'

In the above code 'url' value is 'root/TRecord' and '@SentData' value is '{'JSON values of my TRecord'}'

And to be more detailed about this error code is followed,

function TSQLRestClientURI.ServerTimeStampSynchronize: boolean;
var status: integer;
    aResp: RawUTF8;
begin
  fServerTimeStampOffset := 0.0001; // avoid endless recursive call
  status := CallBackGet('TimeStamp',[],aResp);      // exactly on this line the error throws

I could only find where was the error, but don't know exactly what the error was?

Let me know if you couldn't understand anywhere in this question.

Thanks in advance.

Last edited by aruncs08 (2014-10-27 14:01:23)

Offline

Board footer

Powered by FluxBB