代码如下,运行之后无问题,查看注册表中键值与手工配置完全一样,可是系统的管理工具中虽然有了这个ODBC连接,却没有指向我需要的Execl文件,请问是什么原因呢?
reg := TRegistry.Create;
//建立一个Registry实例
with reg do
begin
REG.RootKey:=HKEY_LOCAL_MACHINE;
//REG.OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources', True);
//设置根键值为HKEY_LOCAL_MACHINE
//找到Software\ODBC\ODBC.INI\ODBC Data Sources
if REG.OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources', True) then
begin
//注册一个DSN名称
REG.WriteString( 'myexecl' ,'Microsoft Excel Driver (*.xls)' );
end
else
begin
//创建键值失败
ShowMessage('增加ODBC数据源失败');
exit;
end;
REG.CloseKey;
//找到或创建Software\ODBC\ODBC.INI\masdsn 写入DSN配置信息
if REG.OpenKey('Software\ODBC\ODBC.INI\myexecl' ,True) then
begin
// REG.WriteBinaryData( 'ReadOnly',BUF,01);
REG.WriteString( 'DBQ',Edit6.Text);
REG.WriteString( 'DefaultDir','F:\');
REG.WriteString( 'Driver' ,'C:\WINDOWS\system32\odbcjt32.dll' );
REG.WriteInteger( 'DriverId' ,790 );
REG.WriteString( 'FIL' ,'excel 8.0;');
REG.WriteInteger( 'SafeTransactions' ,0 );
REG.WriteString( 'UID' ,'');
end
else
//创建键值失败 begin
Showmessage('增加ODBC数据源失败');
exit;
end;
if REG.OpenKey('Engines' ,True) then
begin
if REG.OpenKey('Execl' ,True) then
begin
BUF[1]:=01;
REG.WriteBinaryData( 'FirstRowHasNames',BUF ,1);
REG.WriteString( 'ImplicitCommitSync','');
REG.WriteInteger( 'MaxScanRows' ,8 );
REG.WriteInteger( 'Threads' ,3 );
REG.WriteString( 'UserCommitSync' ,'Yes');
end;
end ; reg.CloseKey;
reg.Free;
//ShowMessage('增加ODBC数据源成功'); end;
reg := TRegistry.Create;
//建立一个Registry实例
with reg do
begin
REG.RootKey:=HKEY_LOCAL_MACHINE;
//REG.OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources', True);
//设置根键值为HKEY_LOCAL_MACHINE
//找到Software\ODBC\ODBC.INI\ODBC Data Sources
if REG.OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources', True) then
begin
//注册一个DSN名称
REG.WriteString( 'myexecl' ,'Microsoft Excel Driver (*.xls)' );
end
else
begin
//创建键值失败
ShowMessage('增加ODBC数据源失败');
exit;
end;
REG.CloseKey;
//找到或创建Software\ODBC\ODBC.INI\masdsn 写入DSN配置信息
if REG.OpenKey('Software\ODBC\ODBC.INI\myexecl' ,True) then
begin
// REG.WriteBinaryData( 'ReadOnly',BUF,01);
REG.WriteString( 'DBQ',Edit6.Text);
REG.WriteString( 'DefaultDir','F:\');
REG.WriteString( 'Driver' ,'C:\WINDOWS\system32\odbcjt32.dll' );
REG.WriteInteger( 'DriverId' ,790 );
REG.WriteString( 'FIL' ,'excel 8.0;');
REG.WriteInteger( 'SafeTransactions' ,0 );
REG.WriteString( 'UID' ,'');
end
else
//创建键值失败 begin
Showmessage('增加ODBC数据源失败');
exit;
end;
if REG.OpenKey('Engines' ,True) then
begin
if REG.OpenKey('Execl' ,True) then
begin
BUF[1]:=01;
REG.WriteBinaryData( 'FirstRowHasNames',BUF ,1);
REG.WriteString( 'ImplicitCommitSync','');
REG.WriteInteger( 'MaxScanRows' ,8 );
REG.WriteInteger( 'Threads' ,3 );
REG.WriteString( 'UserCommitSync' ,'Yes');
end;
end ; reg.CloseKey;
reg.Free;
//ShowMessage('增加ODBC数据源成功'); end;
解决方案 »
- directshow手动连接dspack下AsyncEx Filter错误
- 同样的代码,同一个工程,delphi7怎么有时候可以执行有时候不能执行?
- 线程的调用问题
- 串口接收数据乱码的问题
- Delphi+Access,希望在SQL查询中对数据取整
- 在北京吃小吃应该去什么地方??
- 请问从一颗星到五颗星,每加一颗是多少分?
- 用DateTimeToStr将日期时间转为字符串后,新的时间对应的字符串大,还是晚的时间对应的字符串大?
- 已经知道了TColor的值,怎么转换成RGB值
- 在哪儿能找到Delphi的函数库?(例如:类型转换函数)
- 收购成熟进销存和库存管理源代码
- 关于加载DLL里的Windows菜单的问题——急
注册表路径不对,在HKEY_CURRENT_USER中
并且注册成功后,必须重新启动计算机才能在odbc管理器中看到
所以这样很啰嗦,用户肯定受不了
提示:'[Microsoft][ODBC驱动程序管理器]驱动程序的SQLSetConnectAttr失败'