自动配置ODBC
代码如下:
program Project1;uses
Forms,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}
function sqlconfigDatasource(
hwndparent:integer; frequest:longint;
lpszdriverstring:string; lpszattributes:string):
longbool;stdcall;external'odbccp32.dll';
const
odbc_add_dsn=1;
odbc_config_dsn=2;
odbc_remove_dsn=3;
odbc_add_sys_dsn=4;
odbc_config_sys_dsn=5;
odbc_revove_sys_dsn=6;
begin
Application.Initialize;
sqlconfigdatasource (0,ODBC_add_sys_DSN,
'Microsoft Access Driver(*.MDB)',
'Dsn=passw;DBQ='+extractfilepath(application.exeName)+'password.mdb;'
+'fil=Ms Access;MaxBufferSize=512;Pagetimeout=5;'
+'Description=MDdate');
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
----------------------------------------------------------------------------------
为什么会提示undeclared identfire:'extractfilepath';请问这个函数也要自定议吗,在线急等,高手急救,谢谢
代码如下:
program Project1;uses
Forms,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}
function sqlconfigDatasource(
hwndparent:integer; frequest:longint;
lpszdriverstring:string; lpszattributes:string):
longbool;stdcall;external'odbccp32.dll';
const
odbc_add_dsn=1;
odbc_config_dsn=2;
odbc_remove_dsn=3;
odbc_add_sys_dsn=4;
odbc_config_sys_dsn=5;
odbc_revove_sys_dsn=6;
begin
Application.Initialize;
sqlconfigdatasource (0,ODBC_add_sys_DSN,
'Microsoft Access Driver(*.MDB)',
'Dsn=passw;DBQ='+extractfilepath(application.exeName)+'password.mdb;'
+'fil=Ms Access;MaxBufferSize=512;Pagetimeout=5;'
+'Description=MDdate');
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
----------------------------------------------------------------------------------
为什么会提示undeclared identfire:'extractfilepath';请问这个函数也要自定议吗,在线急等,高手急救,谢谢
解决方案 »
- 请问,用Delphi如何写程序将Excel或txt导入oracle?
- quickrep数据刷新问题?第二次打开预览,还保留以前的数据
- 本人想找份兼职的工作或招聘delphi开发人员的请联系
- 菜鸟一问,如何判断当前 的表记录是否为空?
- 关于好看的界面
- 如何屏蔽 系统的 WIN(就是哪个有WINDOWS图标的毽子)
- 老板毕竟是老板,打工的始终是打工的!!!愤怒中,散分去去晦气。
- 怎样知道一个string中包含另一个string
- 关于 ShellExecute() 函数的问题 (大家讨论区)
- 在线程中SendMessage是否会导致线程的停止?
- 对字段进行整理和排序!
- 请问这么扩大DELPHI应用服务器( 中间层)的用户联接数?(急)
这个单元没引用
function TAdodm.SetRegeditODBC(srvname, dbname, uname, passwd: string): boolean;
var
reg:TRegistry;
begin
reg:=TRegistry.Create ;
reg.RootKey:=HKEY_LOCAL_MACHINE; if reg.OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources',True) then
begin //注册一个DSN名称
reg.WriteString(dbname,'SQL Server');
end ;
reg.CloseKey;
if reg.OpenKey('Software\ODBC\ODBC.INI\ODBC File DSN',True) then
Begin
reg.WriteString('DefaultDSNDir','C:\Program Files\Common Files\ODBC\Data Sources\');
end;
reg.CloseKey;
if reg.OpenKey('Software\ODBC\ODBC.INI\'+dbname,True) then
begin //注册一个DSN名称
reg.WriteString('Driver','SQLSRV32.dll');
reg.WriteString('Description','SQL SERVER');
reg.WriteString('Server',srvname);
reg.WriteString('Database',dbname);
reg.WriteString('LastUser',uname);
reg.WriteString('PassWord',passwd);
end ;
reg.CloseKey;
reg.Free;
end;
AppPath:=ExtractFilePath(Application.ExeName); //取得应用程序的当前路径
GetMem(SysDir,255);
GetSystemDirectory(SysDir,255); //取得WINDOWS系统目录
Path:=String(SysDir);
registry1:=tregistry.Create;
registry1.RootKey:=HKEY_CURRENT_USER;
if registry1.OpenKey('software\odbc\odbc.ini\odbc data sources',true) then
begin
registry1.WriteString('MWKQ1','Microsoft Access Driver (*.mdb)');
registry1.CloseKey;
end;
if registry1.OpenKey('software\odbc\odbc.ini\MWKQ1',true) then
begin
registry1.WriteString('DBQ',apppath+'MWKQ1.mdb');
registry1.WriteString('Driver',path+'\odbcjt32.dll');
registry1.Writeinteger('DriverId',25);
registry1.writestring('FIL','MS Access;');
registry1.WriteInteger('SafeTransactions',0);
registry1.WriteString('UID','');
registry1.CloseKey;
end;
if registry1.OpenKey('software\odbc\odbc.ini\MWKQ1\Engines\Jet',true) then
begin
registry1.writestring('ImplicitCommitSync','Yes');
registry1.writeinteger('MaxBufferSize',512);
registry1.WriteInteger('PageTimeout',10);
registry1.writeinteger('Threads',3);
registry1.WriteString('UserCommitSync','Yes');
end;
registry1.CloseKey ;
registry1.Free;