Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing database: memory problem

Status
Not open for further replies.

wduty

Programmer
Jun 24, 2000
271
US
I am a C++ novice (warning). Recently, I needed to write a simple C++ program that would connect to an Access database and delete certain records. So I went to MSDN and downloaded a little example program called adovc1.exe and rewrote parts of it to get it to do what I want. It works BUT the exe file compiles to over 1.2 MB. Why is it so big? I'm guessing it has to do with the import and usage of msado15.dll?<br><br>Though the program runs OK on my local computer, when I put it on one of our servers the dos prompt gives me a message &quot;Program is too large to fit in memory&quot;.<br><br>What is causing this huge size and memory usage? There's got to be a &quot;lighter&quot; approach to handling databases...<br>Any suggestions appreciated!<br><br> <p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br>
 
Dear Will,<br><br>Change your project settings to use the MFC DLL. This will severely reduce the size of your .EXE file. The MFC DLL should be installed on your server. If it is not then you can install it yourself.<br><br>Based on the information you provided this is only a wild guess. This may not be your problem.<br><br>-pete
 
<br>Well the program is certainly smaller! (about a tenth of its previous size: now 133K).<br><br>However, once again it works locally but not on the server I want to run it in. I received errors indicating that the program couldn't find &quot;Mfc42D.dll&quot; and &quot;Msvcrtd.dll&quot;. So I copied those into the system32 directory on the server. I tried to register them but got an error &quot;Mfc42D.dll was loaded, but the DllRegisterServer entry point was not found.&quot;<br>Anyways, now when I try to run this program on that server it no longer gives me a memory error but instead an ADO error &quot;-2147467262 No Such interface supported&quot;.<br><br>One source of the problem is probably that I am building this on a windows98 machine and trying to run it on NT.<br><br>Even the most basic remarks appreciated. The only experience I have with c++ are simple commandline programs. Interacting with ActiveX and windows is daunting to me.<br><br>Here's a simple version of the program<br>------------------------------------<br>#include &lt;stdio.h&gt;<br>#include &lt;afxdisp.h&gt;<br>#import &quot;c:\program files\common files\system\ado\msado15.dll&quot; rename (&quot;EOF&quot;,&quot;adoEOF&quot;) no_namespace<br>#define CREATEiNSTANCE(sp,riid) { HRESULT _hr =sp .CreateInstance( __uuidof( riid ) ); \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (FAILED(_hr)) _com_issue_error(_hr); }<br>#define RsITEM(rs,x) rs-&gt;Fields-&gt;Item[_variant_t(x)]-&gt;Value<br><br>struct InitOle <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitOle()&nbsp;&nbsp;{ ::CoInitialize(NULL); }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~InitOle() { ::CoUninitialize();&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} _init_InitOle_;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Global Instance to force load/unload of OLE<br><br>void main()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_RecordsetPtr&nbsp;&nbsp;&nbsp;spRS;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_ConnectionPtr&nbsp;&nbsp;spCON;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CString strTmp;<br>try{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CREATEiNSTANCE(spCON,Connection);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spCON-&gt;ConnectionString = &quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=test.MDB;DefaultDir=D:\databases\;}&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spCON-&gt;Open( &quot;test&quot;, &quot;&quot;, &quot;&quot;, -1 );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CREATEiNSTANCE(spRS,Recordset)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spRS-&gt;PutRefActiveConnection( spCON );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spRS-&gt;Open(&quot;SELECT * FROM cart&quot;, vtMissing, adOpenKeyset, adLockBatchOptimistic, -1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while(spRS-&gt;adoEOF == false)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;\n&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf((char*) _bstr_t(RsITEM(spRS,&quot;dts&quot;)));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spRS-&gt;MoveNext();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spRS-&gt;Close();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spCON-&gt;Close();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;catch( _com_error &e) {...}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> }<br>#undef UC<br> <p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br>
 
&gt; ADO error &quot;-2147467262 No Such interface supported&quot;.<br><br>That should be one of two things. You don't have the latest MDAC installed on the server OR you are using an outdated ADO Interface in your code. There are some old samples on MSDN for using ADO Interfaces, make sure you look at the newer ones for examples of using the ADO with ATL.<br><br>Hope this helps<br>-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top