﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-welcome-随笔分类-Oracle</title><link>http://www.cppblog.com/stdyh/category/1992.html</link><description>vc java sdk</description><language>zh-cn</language><lastBuildDate>Mon, 19 May 2008 23:50:44 GMT</lastBuildDate><pubDate>Mon, 19 May 2008 23:50:44 GMT</pubDate><ttl>60</ttl><item><title>VC++.net使用OCCI连接远程Oracle数据库</title><link>http://www.cppblog.com/stdyh/archive/2006/06/20/8739.html</link><dc:creator>dyh</dc:creator><author>dyh</author><pubDate>Tue, 20 Jun 2006 05:07:00 GMT</pubDate><guid>http://www.cppblog.com/stdyh/archive/2006/06/20/8739.html</guid><wfw:comment>http://www.cppblog.com/stdyh/comments/8739.html</wfw:comment><comments>http://www.cppblog.com/stdyh/archive/2006/06/20/8739.html#Feedback</comments><slash:comments>11</slash:comments><wfw:commentRss>http://www.cppblog.com/stdyh/comments/commentRss/8739.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/stdyh/services/trackbacks/8739.html</trackback:ping><description><![CDATA[
		<p>
				<font style="BACKGROUND-COLOR: #ffffff" color="#000000">        由于项目的需要，需要用C++去连Oracle数据库，Oracle版本为10g，在经过n次错误后终于成功连接。<br />        最开始用ADO连，装上客户端以后，在Oracle Net Manager中设置服务命名，测试连接成功，然后<br />设置ODBC数据源，测试也成功，ADO连接串写上"DSN=xxx"就能连上了，但是在释放连接时总是出错，<br />经过多次尝试后放弃，在网上看到Oracle专门为C++提供了连接的接口OCCI，于是尝试采用这种方法。<br />        一、安装Oracle客户端<br />                安装方式选择为管理员。安装完以后设置服务命名。在%ORACLIENTHOME%\NETWORK\ADMIN目录下tnsnames.ora文件记录了服务命名的设置。我的设置如下：<br />                </font>
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font style="BACKGROUND-COLOR: #ffffff" color="#000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</font>
				<font style="BACKGROUND-COLOR: #ffffff">
						<font color="#000000">
								<span style="COLOR: #000000">ORCL_192.168.0.3 =<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  (DESCRIPTION =<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    (ADDRESS_LIST =<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.3)(PORT = 1521))<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    )<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    (CONNECT_DATA =<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />      (SID = orcl)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />      (SERVER = DEDICATED)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    )<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  )<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />ORCL =<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  (DESCRIPTION =<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    (ADDRESS_LIST =<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.3)(PORT = 1521))<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    )<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    (CONNECT_DATA =<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />      (SERVICE_NAME = ORCL_192.168.0.3)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    )<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />  )<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
						</font>
				</font>
		</div>
		<p>
				<font style="BACKGROUND-COLOR: #ffffff" color="#000000">其中192.168.0.3为远程Oracle服务器IP地址<br />设置完以后在Net Manager中测试连接，成功就OK了。<br />        二、设置VC++.net环境<br />        我用的编译器是VS2003，首先在工具---选项中Project添加包含文件%OracleClientHome%\Oci\include<br />添加库文件%OracleClientHome%\Oci\lib\msvc\vc71和%OracleClientHome%\Oci\lib\msvc如果是VC6.0的话就<br />添加%OracleClientHome%\Oci\lib\msvc\vc6。<br />然后设置项目属性，在编译器---链接中添加lib文件，oraocci10d.lib，之后把oraocci10d.dll文件复制到system32目录下，这个文件在VC71目录下。<br />第三步在C++----代码生成中设置运行时库为多线程DLL或是多线程调试DLL，注意这一步设置很重要，<br />没有设置的话会造成getString函数出错。<br />        三、代码<br />        </font>
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<font style="BACKGROUND-COLOR: #ffffff" color="#000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<span style="COLOR: #000000">#include </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">stdafx.h</span>
						<span style="COLOR: #000000">"</span>
				</font>
				<span style="COLOR: #000000">
						<br />
						<font style="BACKGROUND-COLOR: #ffffff" color="#000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include  </font>
				</span>
				<font style="BACKGROUND-COLOR: #ffffff">
						<font color="#000000">
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000">occi.h</span>
								<span style="COLOR: #000000">&gt;</span>
						</font>
				</font>
				<span style="COLOR: #000000">
						<br />
						<font style="BACKGROUND-COLOR: #ffffff" color="#000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						</font>
				</span>
				<font style="BACKGROUND-COLOR: #ffffff">
						<font color="#000000">
								<span style="COLOR: #0000ff">using</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">namespace</span>
						</font>
				</font>
				<font style="BACKGROUND-COLOR: #ffffff">
						<font color="#000000">
								<span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
								<span style="COLOR: #0000ff">using</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">namespace</span>
						</font>
				</font>
				<font style="BACKGROUND-COLOR: #ffffff">
						<font color="#000000">
								<span style="COLOR: #000000"> oracle::occi ;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
								<span style="COLOR: #0000ff">int</span>
						</font>
				</font>
				<font style="BACKGROUND-COLOR: #ffffff">
						<font color="#000000">
								<span style="COLOR: #000000"> main() <br /><img id="Codehighlighter1_102_785_Open_Image" onclick="this.style.display='none'; Codehighlighter1_102_785_Open_Text.style.display='none'; Codehighlighter1_102_785_Closed_Image.style.display='inline'; Codehighlighter1_102_785_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_102_785_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_102_785_Closed_Text.style.display='none'; Codehighlighter1_102_785_Open_Image.style.display='inline'; Codehighlighter1_102_785_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
								<span id="Codehighlighter1_102_785_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.cppblog.com/images/dot.gif" />
								</span>
						</font>
				</font>
				<span id="Codehighlighter1_102_785_Open_Text">
						<font style="BACKGROUND-COLOR: #ffffff">
								<font color="#000000">
										<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Environment</span>
										<span style="COLOR: #000000">*</span>
										<span style="COLOR: #000000"> env</span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000">Environment::createEnvironment(</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">ZHS16GBK</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">UTF8</span>
										<span style="COLOR: #000000">"</span>
								</font>
						</font>
						<font style="BACKGROUND-COLOR: #ffffff">
								<font color="#000000">
										<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #008000">//</span>
										<span style="COLOR: #008000">Environment *env=Environment::createEnvironment(Environment::DEFAULT);</span>
								</font>
						</font>
						<span style="COLOR: #008000">
								<br />
								<font style="BACKGROUND-COLOR: #ffffff" color="#000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								</font>
						</span>
						<span style="COLOR: #000000">
								<br />
								<font style="BACKGROUND-COLOR: #ffffff" color="#000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />     </font>
						</span>
						<span style="COLOR: #0000ff">
								<font style="BACKGROUND-COLOR: #ffffff" color="#000000">string </font>
						</span>
						<font style="BACKGROUND-COLOR: #ffffff">
								<font color="#000000">
										<span style="COLOR: #000000"> mc;<br /><img id="Codehighlighter1_262_713_Open_Image" onclick="this.style.display='none'; Codehighlighter1_262_713_Open_Text.style.display='none'; Codehighlighter1_262_713_Closed_Image.style.display='inline'; Codehighlighter1_262_713_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_262_713_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_262_713_Closed_Text.style.display='none'; Codehighlighter1_262_713_Open_Image.style.display='inline'; Codehighlighter1_262_713_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
										<span id="Codehighlighter1_262_713_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</span>
								</font>
						</font>
						<span id="Codehighlighter1_262_713_Open_Text">
								<font style="BACKGROUND-COLOR: #ffffff">
										<font color="#000000">
												<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        Connection </span>
												<span style="COLOR: #000000">*</span>
												<span style="COLOR: #000000">conn </span>
												<span style="COLOR: #000000">=</span>
												<span style="COLOR: #000000"> env</span>
												<span style="COLOR: #000000">-&gt;</span>
												<span style="COLOR: #000000">createConnection(</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">system</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">, </span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">system</span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">, </span>
												<span style="COLOR: #000000">"</span>
												<span style="COLOR: #000000">orcl_192.168.0.3</span>
												<span style="COLOR: #000000">"</span>
										</font>
								</font>
								<font style="BACKGROUND-COLOR: #ffffff">
										<font color="#000000">
												<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
												<span style="COLOR: #0000ff">try</span>
										</font>
								</font>
								<span style="COLOR: #000000">
										<br />
										<font style="BACKGROUND-COLOR: #ffffff" color="#000000">
												<img id="Codehighlighter1_359_624_Open_Image" onclick="this.style.display='none'; Codehighlighter1_359_624_Open_Text.style.display='none'; Codehighlighter1_359_624_Closed_Image.style.display='inline'; Codehighlighter1_359_624_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
												<img id="Codehighlighter1_359_624_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_359_624_Closed_Text.style.display='none'; Codehighlighter1_359_624_Open_Image.style.display='inline'; Codehighlighter1_359_624_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />         </font>
								</span>
								<span id="Codehighlighter1_359_624_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<font style="BACKGROUND-COLOR: #ffffff" color="#000000">
												<img src="http://www.cppblog.com/images/dot.gif" />
										</font>
								</span>
								<span id="Codehighlighter1_359_624_Open_Text">
										<font style="BACKGROUND-COLOR: #ffffff">
												<font color="#000000">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            Statement </span>
														<span style="COLOR: #000000">*</span>
														<span style="COLOR: #000000">stmt </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> conn</span>
														<span style="COLOR: #000000">-&gt;</span>
														<span style="COLOR: #000000">createStatement(</span>
														<span style="COLOR: #000000">"</span>
														<span style="COLOR: #000000">select * from test1</span>
														<span style="COLOR: #000000">"</span>
												</font>
										</font>
										<font style="BACKGROUND-COLOR: #ffffff">
												<font color="#000000">
														<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            ResultSet </span>
														<span style="COLOR: #000000">*</span>
														<span style="COLOR: #000000">rs </span>
														<span style="COLOR: #000000">=</span>
														<span style="COLOR: #000000"> stmt</span>
														<span style="COLOR: #000000">-&gt;</span>
												</font>
										</font>
										<font style="BACKGROUND-COLOR: #ffffff">
												<font color="#000000">
														<span style="COLOR: #000000">executeQuery();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
														<span style="COLOR: #0000ff">while</span>
														<span style="COLOR: #000000">(rs</span>
														<span style="COLOR: #000000">-&gt;</span>
														<span style="COLOR: #000000">next() </span>
														<span style="COLOR: #000000">==</span>
														<span style="COLOR: #000000"> </span>
														<span style="COLOR: #0000ff">true</span>
												</font>
										</font>
										<font style="BACKGROUND-COLOR: #ffffff">
												<font color="#000000">
														<span style="COLOR: #000000">)<br /><img id="Codehighlighter1_502_556_Open_Image" onclick="this.style.display='none'; Codehighlighter1_502_556_Open_Text.style.display='none'; Codehighlighter1_502_556_Closed_Image.style.display='inline'; Codehighlighter1_502_556_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_502_556_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_502_556_Closed_Text.style.display='none'; Codehighlighter1_502_556_Open_Image.style.display='inline'; Codehighlighter1_502_556_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />            </span>
														<span id="Codehighlighter1_502_556_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
																<img src="http://www.cppblog.com/images/dot.gif" />
														</span>
												</font>
										</font>
										<span id="Codehighlighter1_502_556_Open_Text">
												<font style="BACKGROUND-COLOR: #ffffff">
														<font color="#000000">
																<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                mc</span>
																<span style="COLOR: #000000">=</span>
																<span style="COLOR: #000000">rs</span>
																<span style="COLOR: #000000">-&gt;</span>
																<span style="COLOR: #000000">getString(</span>
																<span style="COLOR: #000000">1</span>
														</font>
												</font>
												<font style="BACKGROUND-COLOR: #ffffff">
														<font color="#000000">
																<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                cout </span>
																<span style="COLOR: #000000">&lt;&lt;</span>
																<span style="COLOR: #000000"> mc </span>
																<span style="COLOR: #000000">&lt;&lt;</span>
														</font>
												</font>
												<span style="COLOR: #000000">
														<font style="BACKGROUND-COLOR: #ffffff" color="#000000"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />            } </font>
												</span>
										</span>
										<span style="COLOR: #000000">
												<br />
												<font style="BACKGROUND-COLOR: #ffffff" color="#000000">
														<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            stmt </font>
										</span>
										<span style="COLOR: #000000">
												<font style="BACKGROUND-COLOR: #ffffff" color="#000000">-&gt; </font>
										</span>
										<font style="BACKGROUND-COLOR: #ffffff">
												<font color="#000000">
														<span style="COLOR: #000000">closeResultSet(rs);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            conn</span>
														<span style="COLOR: #000000">-&gt;</span>
												</font>
										</font>
										<span style="COLOR: #000000">
												<font style="BACKGROUND-COLOR: #ffffff" color="#000000">terminateStatement(stmt);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        } </font>
										</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<font style="BACKGROUND-COLOR: #ffffff" color="#000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />         </font>
								</span>
								<span style="COLOR: #0000ff">
										<font style="BACKGROUND-COLOR: #ffffff" color="#000000">catch </font>
								</span>
								<font style="BACKGROUND-COLOR: #ffffff">
										<font color="#000000">
												<span style="COLOR: #000000"> (SQLException e)<br /><img id="Codehighlighter1_653_676_Open_Image" onclick="this.style.display='none'; Codehighlighter1_653_676_Open_Text.style.display='none'; Codehighlighter1_653_676_Closed_Image.style.display='inline'; Codehighlighter1_653_676_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_653_676_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_653_676_Closed_Text.style.display='none'; Codehighlighter1_653_676_Open_Image.style.display='inline'; Codehighlighter1_653_676_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
												<span id="Codehighlighter1_653_676_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
														<img src="http://www.cppblog.com/images/dot.gif" />
												</span>
										</font>
								</font>
								<span id="Codehighlighter1_653_676_Open_Text">
										<font style="BACKGROUND-COLOR: #ffffff">
												<font color="#000000">
														<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />            cout</span>
														<span style="COLOR: #000000">&lt;&lt;</span>
												</font>
										</font>
										<span style="COLOR: #000000">
												<font style="BACKGROUND-COLOR: #ffffff" color="#000000">e.what();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        } </font>
										</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<font style="BACKGROUND-COLOR: #ffffff" color="#000000">
												<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        env </font>
								</span>
								<span style="COLOR: #000000">
										<font style="BACKGROUND-COLOR: #ffffff" color="#000000">-&gt; </font>
								</span>
								<span style="COLOR: #000000">
										<font style="BACKGROUND-COLOR: #ffffff" color="#000000">terminateConnection(conn);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    } </font>
								</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<font style="BACKGROUND-COLOR: #ffffff" color="#000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Environment::terminateEnvironment(env);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    system( </font>
						</span>
						<font style="BACKGROUND-COLOR: #ffffff">
								<font color="#000000">
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">pause</span>
										<span style="COLOR: #000000">"</span>
								</font>
						</font>
						<font style="BACKGROUND-COLOR: #ffffff">
								<font color="#000000">
										<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
										<span style="COLOR: #0000ff">return</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0</span>
								</font>
						</font>
						<span style="COLOR: #000000">
								<font style="BACKGROUND-COLOR: #ffffff" color="#000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />} </font>
						</span>
				</span>
		</div>
		<p>
				<font style="BACKGROUND-COLOR: #ffffff" color="#000000">orcl_192.168.0.3就是前面设置的连接串。<br />测试成功。以上就是所有的设置过程，唉，还是jdbc好连阿。。。<br /><br />注意，项目属性中运行时库一定要设置为多线程DLL或是多线程调试DLL，否则getString函数就会出错，我在这个问题上也卡了很长时间，单步调试发现是在string对象析购时出错，在网上看到一篇文章得到答案。<br />        原因是由于程序中使用的内存管理多来源于crt提供的例程，而非直接使用操作系统的接口，这些例程都需要维护一些module全局数据（例如维护池、维护空闲块、或者标记已申请的块等等，不同的实现中有不同的作用），当他们被静态连编时，实际上这些“全局数据”就不“全局”了，不同的module各自为政，每份module都有自己的“全局数据”，自身的内存信息不为他人所知，module A的合法内存快自然不可能通得过module B的合法性验证 <br /><br />解决问题的方法有： <br />1、不要跨module传递c++对象，或者避免释放跨module申请的内存 <br /><br />2、将参与合作的module统统以multithreaded dll方式链入crt库，让他们的“全局”数据真正全局，注意，所有有交互的module都需要动态链入crt。 </font>
		</p>
<img src ="http://www.cppblog.com/stdyh/aggbug/8739.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/stdyh/" target="_blank">dyh</a> 2006-06-20 13:07 <a href="http://www.cppblog.com/stdyh/archive/2006/06/20/8739.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>