I am getting an error when creating tables in MS ACCESS when using FireDAC connection (Delphi Xe6).
The A new database file is created and 3 tables are created either using TFDCommand or TFDQuery, the tables do get created, but I always get an error 'Table already exists'. Any suggestions to stop the error being raised.
I do encompass the code in a try...Except routine.
Code:
FDCommand1.CommandText.Text := 'CREATE Table [SampleData] ' +
'([SampleID] INTEGER Primary Key NOT NULL, ' +
' [RiskIDX] INTEGER NULL,' +
' [RefSampleID] Char(10) NULL,' +
' [SerialNumber] Char(60) NULL,' +
' [TestDate] DateTime NULL,' +
' [ResampleDate] DateTime NULL,' +
' [SampleDate] DateTime NULL,' +
' [SamplingPoint] Char(60) NULL,' +
' [LabTech] Char(60) NULL, SampledBy Char(60) NULL,' +
' [Status] Char(60) NULL,' +
' [Source] Char(60) NULL,' +
' [Condition] Char(60) NULL,' +
' [PlotPnt] YESNO,' +
' [Comments] Memo' +
' CONSTRAINT FKSampleId Foreign Key SerialNumber
References AssetInfo SerialNo);';
OR
FDQuery1.SQL.Text := Memo1.text; //Create table SQL command
FDQuery1.Prepare;
FDQuery1.Execute(200,0);
With some experimentation I have found that the FDCommand and FDQuery components do not work in this instance; not even if you check before hand that the tables don't exist. (I not too sure why - but it seems to me that the SQL command is sent twice hence the table exists error). However, the FDConnection.ExecSQL does work. Tried and tested (creates 3 tables with the CONSTRAINTS as I needed it to).
Regards TomD