Recent

Author Topic: [SOLVED] Anyone can tell me why I can't connect?  (Read 559 times)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 371
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
[SOLVED] Anyone can tell me why I can't connect?
« on: May 14, 2025, 09:14:06 pm »
 
Code: Pascal  [Select][+][-]
  1. procedure TFrmCntksMain.FormCreate(Sender: TObject);
  2. begin
  3.   SQLiteLibraryName:= 'sqlite3.dll';
  4.   //-> Connect the CONTACTS table...
  5.   ConnectCntks.DatabaseName:= SysUtils.ExtractFilePath(ParamStr(0)) +
  6.    'ContactsDB.sqlite3';
  7.   ConnectCntks.Connected:= True; //--> ERROR HERE 'Unknown Connector Type' :(
  8.   TransCntks.DataBase:= ConnectCntks;
  9.   TransCntks.Action:= caCommit;
  10.   TransCntks.Active:= True;
  11.   QryCntks.Transaction:= TransCntks;
  12.   QryCntks.Options:= [sqoAutoApplyUpdates];
  13.   DSrcCntks.DataSet:= QryCntks;
  14.   QryCntks.SQL.Text:=
  15.    'SELECT * FROM CONTACTS ContactsDB ORDER BY LASTNAME, FIRSTNAME, MI';
  16.   QryCntks.UpdateSQL.Text:=
  17.    'UPDATE CONTACTS SET CNTKID=:CNTKID, DATESTAMP=:DATESTAMP, LASTNAME=:LASTNAME, '+
  18.    'FIRSTNAME=:FIRSTNAME, MI=:MI, CATEGORY=:CATEGORY, DOB=:DOB, COMPANY=:COMPANY, '+
  19.    'TITLE=:TITLE, SPOUSE=:SPOUSE, ADDRESS=:ADDRESS, ADDRESS2=:ADDRESS2, '+
  20.    'CITYTOWN=:CITYTOWN, COUNTY=:COUNTY, STATEPROV=:STATEPROV, POSTALCODE=:POSTALCODE, '+
  21.    'COUNTRY=:COUNTRY, CELLNO=:CELLNO, MAINPHONE=:MAINPHONE, PHONE=:PHONE, '+
  22.    'FAX=:FAX, EMAIL=:EMAIL, EMAIL2=:EMAIL2, WEBURL=:WEBURL, NOTES=:NOTES '+
  23.    'WHERE CNTKID=:OLD_CNTKID';
  24.  

FormShow Procedure
  QryCntks.Open;
« Last Edit: May 14, 2025, 11:25:41 pm by 1HuntnMan »

CharlyTango

  • Full Member
  • ***
  • Posts: 130
Re: Anyone can tell me why I can't connect?
« Reply #1 on: May 14, 2025, 10:15:08 pm »
as I cannot recognize which object is ConnectCntks I have to rely on guesswork

since you want to connect to SQLite, only TSQLConnector or TSQLite3Connection comes into question.

Based on the error message, I assume that you are using TSQLConnector. This type of connection acts as a kind of proxy connector that is able to handle different connections to different databases. However, the correct unit must be included in the uses clause (in your case SQLite3Conn) and the type of connection must be specified

Code: Pascal  [Select][+][-]
  1. ConnectCntks.ConnectorType:='SQLite3';

but these are only guesses because essential parts are not shown in your code

Lazarus stable, Win32/64

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 371
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Anyone can tell me why I can't connect?
« Reply #2 on: May 14, 2025, 11:25:03 pm »
Fixed it, deleted the TSQLConnector and replaced it with TSQLite3Connection.

CharlyTango

  • Full Member
  • ***
  • Posts: 130
Re: [SOLVED] Anyone can tell me why I can't connect?
« Reply #3 on: May 15, 2025, 08:50:19 am »
TSQLConnector has its justification because you can use a different SQL database just by changing the ConnectorType without having to adapt or compile the program.
And since it is bad style for me to hard-code the user name/password into the program, another parameter is not important.
You just have to be careful to stay close to the SQL-92 standard and avoid individual special functions of each SQL server to stay portable.
But this is not a problem for smaller applications IMO
Lazarus stable, Win32/64

 

TinyPortal © 2005-2018