我一直在为一个允许用户为我的应用程序创建一个新数据库的函数而挣扎--它必须是一个通用的函数,因为有些使用MS Access,有些使用SQLite,还有一些使用MySQL。
我花了几个小时在提供的演示中找不到对我有用的东西。
我想要做的是能够创建一个新的数据库,给定以下参数:提供者、服务器、端口、用户、密码、数据库名称(或文件名)
我有以下创建MS Access的功能,但它并没有做到这一点。
Calling it by SQLConfigDataSource(0, 1, 'Microsoft Access Driver (*.mdb)','CREATE_DB="' + DatabaseName + '"')
Function SQLConfigDataSource(hwndParent: Integer; fRequest: Integer;
lpszDriverString: string; lpszAttributes: string): Integer; stdcall;
var
func : TSQLConfigDataSource;
ODBCHModule: HMODULE;
begin
ODBCHModule := LoadLibrary('odbccp32.dll');
if ODBCHModule = 0 then
raise Exception.Create(SysErrorMessage(GetLastError));
func := GetProcAddress(ODBCHModule,PChar('SQLConfigDataSource'));
if @func = nil then
raise Exception.Create('Error Getting adress for SQLConfigDataSource' + SysErrorMessage(GetLastError));
Result := func(hwndParent, fRequest, lpszDriverString, lpszAttributes);
FreeLibrary(ODBCHModule);
end;发布于 2012-04-21 05:55:14
SQLConfigDataSource(0, ODBC_ADD_DSN, '<driver name>', 'CREATE_DB=<db path>').https://stackoverflow.com/questions/10246915
复制相似问题