编程可以建立ODBC,但其配置“SQL SERVER验证登陆ID的真伪”时,如何设置使其选择第二项“使用用户输入登陆ID和密码的SQL SERVER验证”,并在其下的“登陆ID”和“密码”中输入对应值呢?
解决方案 »
- 求助VC中Fwrite转成delphi如何实现!
- 文件打开 监测 hook实现?
- 送分啦,用DELPHI如果做编辑软件?
- ([在线,给出正确代码就结贴])让一个label显示一个dblabel的内容,dblabel变化,label内容也响应变化,如何写代码呢?
- 一个DBGridEh抬头过滤的问题,急
- 在vb中可以不借助于控件自己编写代码建立Connectiong,在此基础上建立recordset,delphi中如何实现
- 各位大侠好!小弟想请教如何将edit1.text中的内容转换为十六进制,马上给分
- 300分求购源代码!类似delphi的部分功能。
- ini信息文件的读写
- 如何删除一个DCOM服务?
- vb转化为delphi
- 子类继承父类中的抽象方法时出现的问题
var wreg: tregistry;
tmpPath: array[0..255]of char;
sysPath: string;
tmpdbpath:string;
tpath: string;
begin
getsystemdirectory(tmppath,255);
{getsystemdirectory函数能取得Windows系统目录(System目录)的完整路径名}
syspath:=strpas(tmppath);
{strpas()--将null结尾字符串转成一个pascal格式字符串}
tpath:=extractfilepath(application.ExeName);
tmpdbpath:=tpath+'test.mdb';//指定连接数据库的路径
if not fileexists(tmpdbpath) then
begin
messagebox(handle,pchar('找不到存储路径'+tmpdbpath+'的数据文件'),
promsg, mb_ok+mb_iconwarning);
exit;
end; //建立一个Registry实例
wreg:=tregistry.Create;
//-==注册ODBC==-
with wreg do
begin
rootkey:=hkey_local_machine;
if openkey('software\odbc\odbc.ini\odbc data sources',true) then
writestring('regtest','microsoft access driver (*.mdb)')
else
begin
application.MessageBox('ODBC初始化错误',promsg,
mb_ok+mb_iconexclamation);
exit;
end;
closekey; //写入DSN配置信息
if openkey('software\odbc\odbc.ini\regtest',true) then
begin
writestring('dbq',tmpdbpath);//数据库目录
writestring('description','Pasc数据源'); //数据源描述
writestring('driver',syspath+'\odbcjt32.dll'); //驱动程序dll文件
writeinteger('driverid',25);
writestring('fil','MS Access;');
writeinteger('safetransactions',0); //支持的事务操作树目
writestring('uid',''); //用户名称
end
else
begin
application.MessageBox('ODBC初始化错误',promsg,
mb_ok+mb_iconexclamation);
exit;
end;
closekey; if openkey('software\odbc\odbc.ini\regtest\engines\jet',true) then
begin
writestring('implicitcommitsync','yes');
writeinteger('maxbuffersize',2048);//缓冲区大小
writeinteger('threads',3); //支持的线程数目
writeinteger('pagetimeout',10); //页超时
writestring('usercommitsync','yes');
end
else
begin
application.MessageBox('ODBC初始化错误',promsg,
mb_ok+mb_iconexclamation);
exit;
end;
closekey; free;
end; application.MessageBox('用户信息注册成功',promsg,
mb_ok+mb_iconinformation);
end;
//以上是编程建立odbc,就是向注册表内写东西
procedure TCreateODBCDSNfrm.CreateDSNBtnClick(Sender: TObject);
var
registerTemp : TRegistry;
bData : array[ 0..0 ] of byte;
begin
registerTemp := TRegistry.Create;
//建立一个Registry实例
with registerTemp do
begin
RootKey:=HKEY_LOCAL_MACHINE;
//设置根键值为HKEY_LOCAL_MACHINE
//找到Software\ODBC\ODBC.INI\ODBC Data Sources
if OpenKey('Software\ODBC\ODBC.INI
\ODBC Data Sources',True) then
begin //注册一个DSN名称
WriteString( 'MyAccess', 'Microsoft
Access Driver (*.mdb)' );
end
else
begin//创建键值失败
memo1.lines.add('增加ODBC数据源失败');
exit;
end;
CloseKey;
//找到或创建Software\ODBC\ODBC.INI
\MyAccess,写入DSN配置信息
if OpenKey('Software\ODBC\ODBC.INI
\MyAccess',True) then
begin
WriteString( 'DBQ', 'C:\inetpub\wwwroot
\test.mdb' );//数据库目录,连接您的数据库
WriteString( 'Description',
'我的新数据源' );//数据源描述
WriteString( 'Driver', 'C:\PWIN98\SYSTEM\
odbcjt32.dll' );//驱动程序DLL文件
WriteInteger( 'DriverId', 25 );
//驱动程序标识
WriteString( 'FIL', 'Ms Access;' );
//Filter依据
WriteInteger( 'SafeTransaction', 0 );
//支持的事务操作数目
WriteString( 'UID', '' );//用户名称
bData[0] := 0;
WriteBinaryData( 'Exclusive', bData, 1 );
//非独占方式
WriteBinaryData( 'ReadOnly', bData, 1 );
//非只读方式
end
else//创建键值失败
begin
memo1.lines.add('增加ODBC数据源失败');
exit;
end;
CloseKey;
//找到或创建Software\ODBC\ODBC.INI
\MyAccess\Engines\Jet
//写入DSN数据库引擎配置信息
if OpenKey('Software\ODBC\ODBC.INI
\MyAccess\Engines\Jet',True) then
begin
WriteString( 'ImplicitCommitSync', 'Yes' );
WriteInteger( 'MaxBufferSize', 512 );//缓冲区大小
WriteInteger( 'PageTimeout', 10 );//页超时
WriteInteger( 'Threads', 3 );//支持的线程数目
WriteString( 'UserCommitSync', 'Yes' );
end
else//创建键值失败
begin
memo1.lines.add('增加ODBC数据源失败');
exit;
end;
CloseKey;
memo1.lines.add('增加新ODBC数据源成功');
Free;
end;
end;
var wReg: TRegistry;
tmpdbPath: string;
SysPath: array [0..255] of char;
begin
getsystemdirectory(SysPath,255);
{getsystemdirectory函数能取得Windows系统目录(System目录)的完整路径名} wreg:=tregistry.Create;
wreg.RootKey:=hkey_users;
if wreg.OpenKey('S-1-5-21-776561741-789336058-1343024091-500\Software\odbc\odbc.ini\ExamSys',
true) then
begin
wreg.WriteString('Database','ExamSys');
wreg.WriteString('Description','考试系统');
wreg.WriteString('Driver',SysPath+'SQLSRV32.dll');
wreg.WriteString('Server','SPEEDZY'); //SQLSERVER服务器名
wreg.WriteString('Trusted_Connection','Yes');
end
else
begin
application.MessageBox('ODBC初始化错误,本程序即将关闭。'+#13#10+
'关闭后请先检查ODBC是否有错误或未安装,先排除错误或安装后再运行本程序。',
'错误', mb_ok+mb_iconerror);
application.Terminate ;
end;
wreg.CloseKey; if wreg.OpenKey('S-1-5-21-776561741-789336058-1343024091-500\Software\odbc\odbc.ini\ODBC Data Sources',
false) then
wreg.WriteString('ExamSys','SQL Server')
else
begin
application.MessageBox('ODBC初始化错误,本程序即将关闭。'+#13#10+
'关闭后请先检查ODBC是否有错误或未安装,先排除错误或安装后再运行本程序。',
'错误', mb_ok+mb_iconerror);
application.Terminate ;
end;
wreg.CloseKey; //
end;
princesd(中原) :能说说是哪个参数呢,我看不出来!