#1 2014-10-02 04:14:33

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

Unidac5.11 Connect Error

when I use Unidac Connect to SQL Server

  fConnection := TSQLDBUniDACConnectionProperties.Create(
  TSQLDBUniDACConnectionProperties.URI(TSQLDBDefinition.dMSSQL,
  '127.0.0.1;Port=8829;Database=Nuoxin'),'Nuoxin', 'sa', 'dev');

I got some error Can't not open SQL Server

constructor TSQLDBUniDACConnection.Create(aProperties: TSQLDBConnectionProperties);
var options: TStrings;
    PortNumber, i: Integer;
begin
  inherited Create(aProperties);
  fDatabase := TUniConnection.Create(nil);
  fDatabase.ProviderName := UTF8ToString(fProperties.ServerName);
  case aProperties.DBMS of
  dSQLite, dFirebird, dPostgreSQL, dMySQL, dDB2:
    fDatabase.Database := UTF8ToString(fProperties.DatabaseName);
  else
    fDatabase.Server := UTF8ToString(fProperties.DatabaseName);
  end;
  options := (fProperties as TSQLDBUniDACConnectionProperties).fSpecificOptions;
  if fDatabase.Server='' then // see TSQLDBUniDACConnectionProperties.URI()
    fDatabase.Server := options.Values['Server'];
  if fDatabase.Database='' then
    fDatabase.Database := options.Values['Database'];
  if (fDatabase.Port=0) and TryStrToInt(options.Values['Port'],PortNumber) then
    fDatabase.Port := PortNumber;
  fDatabase.Username := UTF8ToString(fProperties.UserID);
  fDatabase.Password := UTF8ToString(fProperties.PassWord);
  for i := 0 to options.Count-1 do
    if FindRawUTF8(['Server','Database','Port'],
        StringToUTF8(options.Names[i]),false)<0 then
      fDatabase.SpecificOptions.Add(options[i]);
end;


case aProperties.DBMS of
  dSQLite, dFirebird, dPostgreSQL, dMySQL, dDB2:
    fDatabase.Database := UTF8ToString(fProperties.DatabaseName);
  else
    fDatabase.Server := UTF8ToString(fProperties.DatabaseName);
  end;

Fixed:

case aProperties.DBMS of
   dSQLite, dFirebird, dPostgreSQL, dMySQL, dDB2:
      fDatabase.Database := UTF8ToString(fProperties.DatabaseName);
  end;

Now It work

Offline

#2 2014-10-02 08:45:19

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

Re: Unidac5.11 Connect Error

What is the error?
Why not set the database name as parameter only, and not in the connection string.

We do not have issues in PerfTest.dpr to connect to MSSQL via UniDAC using:

    Test(TSQLDBUniDACConnectionProperties,UNIDAC_PROVIDER[dMSSQL],
      '(localdb)\v11.0','','',' MSSQL2012',false);
    Test(TSQLDBUniDACConnectionProperties,UNIDAC_PROVIDER[dMSSQL],
      '.\SQLExpress','','',' MSSQL2008',false);

Offline

#3 2014-10-02 10:53:41

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

Re: Unidac5.11 Connect Error

@ab

Thank for reply. I think is the  URI  what i enter.

How to solve unicode chartset

Env:
Database:   SQL Server 2000
DBAccss: Unidac, Zeoslib

    DBStatement := FConnection.NewConnection.NewStatement;
     DBStatement.Prepare('SELECT F_ID,F_CODE,F_NAME FROM TB_PRODUCT_ATTRIBUTE', true);
     DBStatement.ExecutePreparedAndFetchAllAsJSON(true,ResultJson);
     Memo1.Lines.Add(ResultJson);

Result

[{"F_ID":975617,"F_CODE":"0018","F_NAME":"P639触摸屏"},{"F_ID":975618,"F_CODE":"0019","F_NAME":"高科GK757"},{"F_ID":975619,"F_CODE":"0020","F_NAME":"和信C001"},{"F_ID":975620,"F_CODE":"0021","F_NAME":"金鹏S1618"},{"F_ID":975621,"F_CODE":"0022","F_NAME":"联通充值卡100"},{"F_ID":975622,"F_CODE":"0023","F_NAME":"联通充值卡1500"},{"F_ID":975623,"F_CODE":"0024","F_NAME":"联想MA166T"},{"F_ID":975624,"F_CODE":"0025","F_NAME":"TD IMX135 FUJIFILM MODULE"},{"F_ID":975625,"F_CODE":"0026","F_NAME":"天语A905(电信)"},{"F_ID":975626,"F_CODE":"0027","F_NAME":"天语A906(电信)"},{"F_ID":975627,"F_CODE":"0028","F_NAME":"天语D780(电信)"},{"F_ID":975628,"F_CODE":"0029","F_NAME":"天语D788(电信)"},{"F_ID":975629,"F_CODE":"0030","F_NAME":"亿和源L4000"},{"F_ID":975630,"F_CODE":"0031","F_NAME":"英华达A110(电信)"},{"F_ID":975631,"F_CODE":"0032","F_NAME":"英华达C150"},{"F_ID":978213,"F_CODE":"0040","F_NAME":"话费充值"},{"F_ID":979557,"F_CODE":"0042","F_NAME":"品牌分类 3333"}]

Test Data

 CREATE TABLE TB_EMPLOYEE
( F_ID BIGINT PRIMARY KEY,
  F_CODE VARCHAR(32),
  F_NAME VARCHAR(64]
)
 INSERT INTO TB_EMPLOYEE(F_ID,F_CODE,F_NAME) SELECT 1, '00', '测试‘) union all  SELECT  2, '01', '测试1‘)  SELECT 2, '02', '测试3‘)
 

Offline

#4 2014-10-02 12:58:30

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

Re: Unidac5.11 Connect Error

I GOT  ..Utf8  thanks. it's very simple , i like it

Offline

#5 2014-10-02 15:33:19

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

Re: Unidac5.11 Connect Error

Zeos is much faster than unidac with mORMot, BTW.

Offline

Board footer

Powered by FluxBB