看看我动态创建ODBC的程序(很简单),为什么运行了,却没有任何结果?(20分)

  • 主题发起人 主题发起人 8341
  • 开始时间 开始时间
8

8341

Unregistered / Unconfirmed
GUEST, unregistred user!
unit odbc;<br>interface<br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br>&nbsp;const<br>&nbsp; &nbsp;c = 'DSN=MYSQL'#0+<br>&nbsp; &nbsp; &nbsp; &nbsp;'DESCRIPTION=SQLConfigDSN Sample'#0 +<br>&nbsp; &nbsp; &nbsp; &nbsp;'SERVER=(local)'#0 +<br>&nbsp; &nbsp; &nbsp; &nbsp;'ADDRESS='#0 +<br>&nbsp; &nbsp; &nbsp; &nbsp;'NETWORK='#0 +<br>&nbsp; &nbsp; &nbsp; &nbsp;'DATABASE=pubs'#0#0;<br>&nbsp;const<br>&nbsp; &nbsp;ODBCCP32 &nbsp;= 'ODBCCP32.dll';<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>function SQLConfigDataSource(hWnd: HWND; Request: LongInt; DriverType: PChar;<br>&nbsp;Attributes: PChar): BOOL; stdcall;<br><br>var<br>&nbsp; Form1: TForm1;<br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp;try<br>&nbsp; &nbsp;SQLConfigDataSource(0, 4, 'SQL Server', c);<br>&nbsp;except<br>&nbsp; &nbsp;showmessage('创建错误!');<br>&nbsp;end;<br>end;<br><br>function SQLConfigDataSource; external ODBCCP32 name 'SQLConfigDataSource';<br><br>end.<br><br>运行后,也没有报错,但是在ODBC数据原中却没有任何新的项目出现,注册表也没有变化,怎么回事?
 
对了,我是win98+d6
 
var<br>&nbsp; registry1: TRegistry;<br>&nbsp; appPath: string;<br>begin<br>&nbsp; registry1 := tregistry.Create;<br>&nbsp; registry1.RootKey := HKEY_CURRENT_USER;<br>&nbsp; if registry1.OpenKey('software/odbc/odbc.ini/odbc data sources', true) then<br>&nbsp; begin<br>&nbsp; &nbsp; registry1.WriteString('qnsb', 'Microsoft Access Driver (*.mdb)');<br>&nbsp; &nbsp; registry1.CloseKey;<br>&nbsp; end;<br><br>&nbsp; if registry1.OpenKey('software/odbc/odbc.ini/qnsb', true) then<br>&nbsp; begin<br>&nbsp; &nbsp; apppath := ExtractFilePath(Application.ExeName); //程序路径<br>&nbsp; &nbsp; registry1.WriteString('DBQ', apppath + 'qnsb.mdb');<br>&nbsp; &nbsp; registry1.WriteString('Driver', '/odbcjt32.dll');<br>&nbsp; &nbsp; registry1.Writeinteger('DriverId', 25);<br>&nbsp; &nbsp; registry1.writestring('FIL', 'MS Access;');<br>&nbsp; &nbsp; registry1.WriteInteger('SafeTransactions', 0);<br>&nbsp; &nbsp; registry1.WriteString('UID', '');<br>&nbsp; &nbsp; registry1.CloseKey;<br>&nbsp; end;<br><br>&nbsp; if registry1.OpenKey('software/odbc/odbc.ini/gyyb/Engines/Jet', true) then<br>&nbsp; begin<br>&nbsp; &nbsp; registry1.writestring('ImplicitCommitSync', 'Yes');<br>&nbsp; &nbsp; registry1.writeinteger('MaxBufferSize', 512);<br>&nbsp; &nbsp; registry1.WriteInteger('PageTimeout', 10);<br>&nbsp; &nbsp; registry1.writeinteger('Threads', 3);<br>&nbsp; &nbsp; registry1.WriteString('UserCommitSync', 'Yes');<br>&nbsp; end;<br>&nbsp; registry1.CloseKey;<br>&nbsp; registry1.Free;<br>你看看,这是我的关于access的odbc注册程序
 
app2001:<br>我觉得直接操作注册表,会遇到兼容问题,比如在98下和2000下,XP下可能位置不一样,所以我尽量避免用。
 
那你所说的动态创建odbc又是怎么回事呢,我个人认为虽说各系统间略有差别,但可以区别对待,先判断操作系统版本,再针对操作,我这么做的目的,只是为了最大限度的方便用户,必竟要求每一个用户都要学会自己建立ODBC的话,也实在有些难为太多用户了,你认为呢?
 
接受答案了.
 
后退
顶部