📄 90591.htm
字号:
<html xmlns="http://www.w3.org/TR/xhtml1/strict"> <head> <title>天极网</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"></meta> <meta http-equiv="Pragma" content="no-cache"></meta> <meta http-equiv="expires" content="Mon,12 May 1998 00:36:05 GMT"></meta> <link rel="stylesheet" href="/xslimages/css/cpcw.css"></link> </head> <style>.nava { font-size: 9pt}.font1{font-size: 10.5pt}</style> <body bgcolor="#FFFFFF" topmargin="2"><table width="760" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td width="20%" rowspan="3" valign="top" align="center"><table width="95%" border="1" cellspacing="0" cellpadding="0" height="60" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF"><tr valign="middle" align="center"><td><div align="center"><span class="nava">天极硬件,新闻及时<br>资料详尽,敬请关注<br><a href="/33554432/35651584/yingjian.htm">www.myhard.com</a></span></div></td></tr></table></td><td width="57%" valign="bottom" rowspan="3" align="center"><div align="center"><script language="JavaScript" src="http://ad.cpcw.com/js/school.js"></script></div></td><td width="20%" valign="top" rowspan="3" align="center"><table width="95%" border="1" cellspacing="0" cellpadding="0" height="60" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF"><tr valign="middle" align="center"><td><div align="center"><span class="nava">好又多电子商务<br>让您一点动心<br><a href="http://www.hoyodo.com">www.hoyodo.com</a></span></div></td></tr></table></td></tr><tr></tr><tr></tr></table><table width="760" border="0" cellspacing="0" cellpadding="0" height="70" align="center"><tr><td width="145" valign="bottom" rowspan="3"><img src="/xslimages/content/logo.gif" width="140" height="60"></img></td><td colspan="3" width="100%" height="33" align="center"><a href="/" target="_blank">首页</a>| <a href="/33554432/36700160/news.htm" target="_blank">新闻中心</a>| <a href="/33554432/50331648/business.htm" target="_blank">企业中心</a>| <a href="/33554432/41943040/caijing.htm" target="_blank">财经中心</a>| <a href="/33554432/39845888/fashion.htm" target="_blank">时尚中心</a>| <a href="/33554432/35651584/yingjian.htm" target="_blank">硬件中心</a>| <a href="/33554432/34603008/school.htm" target="_blank">学习中心</a>| <a href="/33554432/37748736/game.htm" target="_blank">游戏中心</a>| <a href="/33554432/38797312/ziyuan.htm" target="_blank">资源中心</a>| <a href="http://www.hoyodo.com/" target="_blank">社区</a>| <a href="http://training.yesky.com/" target="_blank">网校</a></td></tr><tr><td colspan="3" width="78%" height="20" align="right"><b>中心栏目:<a href="http://www.mydown.com" target="_blank"><font color="#FF0000"><u>红辣椒软件下载</u></font></a></b><a href="http://soft.yesky.com" target="_blank"> 软件之窗 </a><a href="http://desktop.yesky.com" target="_blank">天极桌面网 </a><a href="http://art.yesky.com" target="_blank">美工教室 </a><a href="http://itdreamer.yesky.com" target="_blank">程序方舟 </a><a href="http://homepage.yesky.com" target="_blank">网页陶吧 </a><a href="http://safe.yesky.com" target="_blank">安全之路</a><a href="http://soft.yesky.com" target="_blank"></a></td></tr></table><table align="center" border="0" cellpadding="0" cellspacing="0" width="760"><tbody><tr bgcolor="#333333"><td colspan="2" height="1"></td></tr><tr><td bgcolor="#ff9900" height="16" valign="bottom" width="72%"><font color="#000000"><b><font color="#ffffff">学 习 中 心</font></b></font></td><td bgcolor="#6699cc" height="16" width="28%"><div align="center"><font face="Arial, Helvetica, sans-serif"><b><font color="#ffffff">N E T S C H O O L</font></b></font></div></td></tr><tr bgcolor="#333333"><td colspan="2" height="1"></td></tr></tbody></table><table align="center" border="0" cellpadding="0" cellspacing="0" width="760" bgcolor="#eeeeee"><td colspan="2" height="28"><div align="center"><a href="/33554432/34603008/34635776/34636800/34636832/schoolinverse1.htm" target="_blank"><font color="#000000">HTML</font></a><font color="#000000"> _</font><a href="/33554432/34603008/34635776/34636800/34636864/schoolinverse1.htm" target="_blank"><font color="#000000">JavaScript</font></a><font color="#000000"> _</font><a href="/33554432/34603008/34635776/34636800/34636928/schoolinverse1.htm" target="_blank"><font color="#000000">CSS</font></a><font color="#000000"> _ <a href="/33554432/34603008/34635776/34637824/34637952/schoolinverse1.htm" target="_blank"><font color="#000000"> PHP </font></a><font color="#000000"> _ </font></font><a href="/33554432/34603008/34635776/34637824/34637888/schoolinverse1.htm" target="_blank"><font color="#000000">ASP</font></a><font color="#000000"> _</font><a href="http://www.yesky.com/33554432/34603008/34635776/34637824/34637920/schoolinverse1.htm" target="_blank"><font color="#000000">Perl</font></a><font color="#000000"> _</font><a href="/33554432/34603008/34635776/34638848/34638880/schoolinverse1.htm" target="_blank"><font color="#000000">Dreamweaver</font></a><font color="#000000"> _</font><a href="/33554432/34603008/34635776/34639872/34639904/schoolinverse1.htm" target="_blank"><font color="#000000">XML</font></a><font color="#000000"> _</font><a href="http://www.yesky.com/33554432/34603008/34734080/schoolinverse2.htm" target="_blank"><font color="#000000">病毒</font></a><font color="#000000"> _</font><a href="http://www.yesky.com/67108864/68157440/68419584/inverse2.htm" target="_blank"><font color="#000000">程序开发</font></a><font color="#000000"> _</font><a href="http://www.yesky.com/33554432/34603008/34799616/34800640/schoolinverse1.htm" target="_blank"><font color="#000000">Email</font></a><font color="#000000"> _</font><a href="http://www.yesky.com/33554432/34603008/34897920/34898944/schoolinverse1.htm" target="_blank"><font color="#000000">Windows 9x</font></a><font color="#000000"> _</font><a href="/33554432/34603008/34897920/34900992/schoolinverse1.htm" target="_blank"><font color="#000000">Linux</font></a><font color="#000000"> _</font><a href="/33554432/34603008/34963456/34966528/schoolinverse1.htm" target="_blank"><font color="#000000">WPS</font></a><font color="#000000"> _</font><a href="http://www.yesky.com/33554432/34603008/34963456/34964480/schoolinverse1.htm" target="_blank"><font color="#000000">Word</font></a></div></td></table><table width="760" border="0" cellspacing="0" cellpadding="0" height="30" align="center"><tr><td align="left" valign="bottom"><span class="nava"><span class="nava"><a href="/index.htm">首页</a>→ <a href="/33554432/34603008/school.htm">学习中心</a>→ <a href="/33554432/34603008/34668544/schoolinverse2-pro.htm">程序方舟</a>→ <a href="/33554432/34603008/34668544/34672640/schoolinverse2.htm">技巧经验</a>→ <a href="/33554432/34603008/34668544/34672640/34672672/schoolinverse1.htm">DELPHI技巧</a>→ </span></span></td><td width="2%"></td></tr></table><table width="760" border="0" cellspacing="0" cellpadding="0" align="center"><tr><td colspan="3" valign="top" width="75%"><table width="98%" border="0" cellspacing="1" cellpadding="1" bgcolor="#000000"><tr bgcolor="#FFFFFF"><td width="100%" colspan="4" align="left"><table width="95%" align="center"><tr><td class="font1"><p align="center"><br><font size="3">在DELPHI程序中动态设置ODBC数据源 </font><br><span class="nava"><font color="#CC9933">2000-07-04· -·-</font></span></p><p><font color="#ffffff">----</font> 在DELPHI数据库应用程序中,我们访问数据库通常有两种方法.一种是通过BDE数据库搜索引擎,即利用DELPHI自带的数据库驱动程序,这种方法的优点是速度快,但应用范围有限,当数据库版本更新时,有可能不能用于操作新的数据库;另一种方法是通过ODBC,这种方法的优 点是可以随操作系统(如WINDOWS)提供,作为标准接口能适应多种数据库,缺点是速度慢.在编 程时,我们可以根据需要选择其中的一种方法. <p><font color="#ffffff">----</font> 在利用ODBC访问数据库时,通常的方法时是在ODBC管理面板中设置一个ODBC系统数据源 (系统DSN),然后在DBD中或在程序中设置一个数据库别名(Alias)对应该DSN,这样就可以如愿以 偿地操作数据库了.相信用DELPHI做过数据库应用的程序员对这方面已经很熟悉了,笔者就不多 说了.在实际应用中,笔者曾遇到过这样的情况,我们的数据库应用程序是依靠ODBC系统数据源 访问和操作数据库的,应用程序运行一直良好,直到某一天,一个对WINDOWS系统较为熟悉但又不 太精通的用户不慎修改或删除了我们预先设置的系统DSN...... <p><font color="#ffffff">----</font> 于是,笔者就开始研究怎么在程序中动态地设置ODBC系统DSN的内容,这样就可以增加自己程 序的坚固性了.经过整整一天对WINDOWS注册表的研究,终于找到了ODBC管理程序设置DSN的秘密 ("天地自有公道,付出总会回报!",不是做广告!),现写出来与大家共享,也请高手指教. <p><font color="#ffffff">----</font> ODBC管理程序设置DSN的秘密在注册表中,不信可以到HKEY_LOCAL_MACHINE\Software\ODBC去看看,肯定让你感觉已经成功了一半. <p><font color="#ffffff">----</font> 首先来看看系统中已安装的ODBC数据库驱动程序.在HKEY_LOCAL_MACHINE\Software\ODBC\ ODBCInst.INI中,存放着已经安装了的ODBC数据库驱动程序的信息,从这里可以查到已安装的ODBC数 据库驱动程序对应的DLL文件等信息.在ODBCInst.INI\ODBC Drivers的各个键值中,键名是驱动程序 名称(如Microsoft Access Driver(*.mdb)),键值为“Installed”,表示驱动程序已安装.在 ODBCInst.INI\DriverName(DriverName为一个驱动程序名称,如Microsoft Access Driver(*.mdb)) 中,有驱动程序的详细信息,我们主要从这里获得ODBC驱动程序对应的DLL文件的路径和文件名,即 键名Driver的键值,一般为"C:\WINDOWS\SYSTEM\FileName.DLL". <p><font color="#ffffff">----</font> 然后来看系统DSN的注册信息,在HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI中,存放着系统 DSN的注册信息,我们在ODBC管理面板设置的DSN参数就在这里. <p><font color="#ffffff">----</font> 下面来看看创建一个ODBC系统DSN的步骤,即我们在ODBC管理面板中完成参数设置后,ODBC管理 程序是怎么在注册表中注册DSN信息的.以创建一个名称为MyAccess的Ms Access97类型的系统DSN为例, 我们指定的参数主要有数据库类型(Microsoft Access Driver(*.mdb))、数据源名称(MyAccess)、 数据源描述(我的ACCESS)、数据库路径(C:\Inetpub\wwwroot\Test.mdb),其它参数如用户名称、 用户密码、独占、只读、系统数据库、默认目录、缓冲区大小、扫描行数、页超时等采用系统 缺省参数.这时,注册系统DSN一般应有以下几个步骤: <p><font color="#ffffff">----</font> 1.在HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\ODBC Data Sources中增加一个字符串键值,为MyAccess = Microsoft Access Driver(*.mdb),其中分别为数据源名称和数据库类型.这是在注册表中注册一个系统DSN名称. <p><font color="#ffffff">----</font> 2.在HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI中创建一个子键(SubKey)MyAccess,即创建一个键为HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\MyAccess,然后在其下创建一些键值,详细描述一个系统DSN的配置信息,主要信息有([]中的内容为笔者注释): <pre> DBQ=C:\Inetpub\wwwroot\Test.mdb [字符串,表示数据库路径] Description=我的ACCESS [字符串,表示数据库描述] Driver=C:\PWIN98\System\odbcjt32.dll [字符串,表示驱动程序,可见ODBCINST.INI] DriverId=0x00000019(25) [数字,表示驱动程序标识,不能改变] FIL=Ms Access; [字符串,可能与过滤Filter有关] SafeTransaction=0x00000000 [数字,可能表示支持事务性操作的个数] UID="" [字符串,表示用户名称,此处为空字符串]</pre><p><font color="#ffffff">----</font> 3.在HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\MyAccess中创建一个子键(SubKey)Engines, 再在其下创建子键(SubKey)Jet,即创建一个键为 HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\MyAccess\Engines\Jet,然后在其下创建一些 键值,详细描述一个系统DSN的数据库引擎配置信息,主要信息有([]中的内容为笔者注释): <pre> ImplicitCommitSync=Yes [字符串,可能表示是否立即反映数据修改] MaxBufferSize=0x00000200(512) [数字,表示缓冲区大小] PageTimeout=0x00000005(5) [数字,表示页超时] Threads=0x00000003(3) [数字,可能表示支持的最大线程数目] UserCommitSync=Yes [字符串,可能表示是否立即将数据修改反映到用户]</pre><p><font color="#ffffff">----</font> 以上是建立一个系统DSN的基本信息(其它信息如选项或高级选项等信息也在这里设置,只不过因采用默认 信息,注册表里没有列出),我们在程序中按上述步骤操作注册表,同样也能增加一个系统DSN或修改其配置. 在下面的例子程序中,将按以上步骤建立一个系统DSN,请注意程序中的注释. <pre>{*******************************************************在本程序中,将创建一个ODBC系统数据源(DSN),数据源名称:MyAccess 数据源描述:我的新数据源数据库类型:ACCESS97对应数据库:C:\Inetpub\wwwroot\test.mdb*******************************************************}{ 注意应在USES语句中包含Registry }procedure TForm1.Button1Click(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 ); //非独占方式
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -