Some time ago, during the project process, we encountered problems with data sources when we required to dynamically load data from different databases. Of course, the DBF table that cannot be connected with ADOQUERY (the patch version was not downloaded, but it was later found that it can also be connected) must be built with ODBC. To perform connection processing, ODBC must be dynamically established to eliminate the possibility of users deleting ODBC. Below I will write down the API function prototype and the statements to create SQLSERVER and DBF tables to share (of course SQLSERVER does not need to be created in ADO state).
SQLConfigDataSource(hwndParent: Integer; fRequest: Integer;lpszDriverString: String; lpszAttributes: String): Integer;
Use in calling state:
function SQLConfigDataSource(hwndParent: Integer; fRequest: Integer;lpszDriverString: String; lpszAttributes: String): Integer;stdcall;external 'ODBCCP32.DLL';
Establish SQLSERVER ODBC:
SQLConfigDataSource(0, ODBC_ADD_SYS_DSN,'SQL Server','DSN=Record_ODBC'+ chr(0) +'Server=(local)'+ chr(0) +'Database=master'+ chr(0) +'Description=DragonPC SQLServer ODBC Source'+ chr(0));
{DSN: Your ODBC data source name.
Server: The name of your database server. Use (local) to refer to the database installed on your local computer. Note: The latest SQL Server 2000 supports one computer running multiple SQL Server services. At this time, you need to specify the InstanceName of SqlSever.
Address: Specify the network IP address of the SQL Server server.
Database: Specify the default database name.
Language: Specify the default language.
Description: Remarks information. }
Create DBF table ODBC:
SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, 'Microsoft Visual FoxPRo Driver' + CHR(0), 'dsn=SourceTable' + CHR(0) + 'BackgroundFetch=Yes' + CHR(0) + 'Description=descripcion de la conexion' + CHR (0) + 'Exclusive=No' + CHR(0) +sourcedbstr + CHR(0) +'Sourcetype=DBF');
Everything else is the same, except that it took a long time to create and debug the DBF table. I hope you won’t waste time by writing it down.
Note: The above content is only for reference by beginners who encounter similar problems.