关于ODBC的问题(50分)

  • 主题发起人 主题发起人 jackl
  • 开始时间 开始时间
J

jackl

Unregistered / Unconfirmed
GUEST, unregistred user!
我用程序来写ODBC的创建:我想创建ACCESS数据源的ODBC,创建SQL_Server数据库的ODBC是
调用WinNT/System32/ODBCCP32.DLL,我想问的是ACCESS数据库是调用哪个Dll呢?
谢谢各位大侠!麻烦列出具体用法!
 
关于动态创建ODBC数据源:
const
ODBC_ADD_DSN = 1; // ' Add data source
ODBC_CONFIG_DSN = 2; // ' Configure (edit) data source
ODBC_REMOVE_DSN = 3 ;// ' Remove data source

首先声明一个API函数:
Function SQLConfigDataSource(hwndParent,fRequest:Longint;lpszDriver:string;lpszAttributes:string):Longint; stdcall;external 'ODBCCP32.DLL';

//添加一个Access数据源
function AddAccessODBC(SourceName,DatabaseName,Desc,password:string):boolean;
var intRet:longint;
strDriver:string;
strAttributes: string;
begin
strDriver:= 'Microsoft Access Driver (*.mdb)';// 'Set the attributes delimited by null.
strAttributes:= ('UID=admin'#0'DESCRIPTION='+Desc+#0'UserCommitSync=Yes'#0'Threads=3'#0'SafeTransactions=0'#0'PageTimeout=5'#0'MaxScanRows=8'#0'DSN='+SourceName+#0'MaxBufferSize=512'#0'ImplicitCommitSync=Yes'#0'FIL=MS Access'#0'DriverId=25'#0'DBQ='+DatabaseName+#0'PWD='+password+#0);
//上面的默认参数你可以自己修改
intRet:= SQLConfigDataSource(0, ODBC_ADD_DSN, strDriver, strAttributes);
result:=(intRet<>0);
end;

//删除一个数据源
function DelAccessODBC(SourceName,DatabaseName,Desc,password:string):boolean;
var intRet:longint;
strDriver:string;
strAttributes: string;
begin
strDriver:= 'Microsoft Access Driver (*.mdb)';// 'Set the attributes delimited by null.
strAttributes:= ('UID=admin'#0'DESCRIPTION='+Desc+#0'UserCommitSync=Yes'#0'Threads=3'#0'SafeTransactions=0'#0'PageTimeout=5'#0'MaxScanRows=8'#0'DSN='+SourceName+#0'MaxBufferSize=512'#0'ImplicitCommitSync=Yes'#0'FIL=MS Access'#0'DriverId=25'#0'DBQ='+DatabaseName+#0'PWD='+password+#0);
intRet:= SQLConfigDataSource(0, ODBC_REMOVE_DSN, strDriver, strAttributes);
result:=(intRet<>0);
end;
 
接受答案了.
 
后退
顶部