* * *

Author Topic: Cannot Create Database  (Read 303 times)

Deepaak

  • Sr. Member
  • ****
  • Posts: 420
Cannot Create Database
« on: August 11, 2017, 10:49:41 am »
Hi guys, I am unable to execute the following code in lazarus, where-as this code works fine in delphi. I am stuck. Even upgrading project don't work


Code: Pascal  [Select]
  1. {$APPTYPE CONSOLE}
  2. {$mode objfpc} {$H+}
  3.  
  4.  
  5. uses
  6.   ActiveX,
  7.   ComObj,
  8.   SysUtils;
  9.  
  10. procedure CreateSQLCeDatabase(const DataBase : string);
  11. Var
  12.   Catalog : Variant;
  13.   ConnectStr : String;
  14.  
  15. begin
  16.   Catalog := CreateOleObject('ADOX.Catalog');
  17.  
  18.   ConnectStr := 'Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0;';
  19.   ConnectStr := ConnectStr + 'Data Source=' +  DataBase +';';
  20.   Catalog.Create(ConnectStr);
  21.  
  22.   //Catalog.Create(Format('Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0;Data Source=%s',[DataBase]));
  23. end;
  24.  
  25. begin
  26.  try
  27.     CoInitialize(nil);
  28.     try
  29.       //CreateSQLCeDatabase('C:\Data\abc.sdf');
  30.       CreateSQLCeDatabase('C:\\Data\\abc.sdf');
  31.     finally
  32.      CoUninitialize;
  33.     end;
  34.  except
  35.     on E:EOleException do
  36.         Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
  37.     on E:Exception do
  38.         Writeln(E.Classname, ':', E.Message);
  39.  end;
  40.  Writeln('Press Enter to exit');
  41.  Readln;
  42. end.          
  43.  

Ooops Holiday season is offline now.

Adri

  • New member
  • *
  • Posts: 15
Re: Cannot Create Database
« Reply #1 on: August 13, 2017, 11:56:20 am »
Hi,

I am just a beginner, but you might try to modify your mode. I think it is $delphi. And you might give some more details like current version and OS used. And any error details you receive now. Succes!

Adri

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus