|
hi,
i want to create only one connection to my db in my app.
im trying to do myConn.Open() in the InitInstance() function in my App but it throws me an exception. what should i do?!
|
|
|
|
|
Avi Laviad wrote:
...but it throws me an exception. what should i do?!
How about telling us what the exception is, or maybe what the code looks like? It's hard to provide anything useful with the little bit of information you've provided.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
well, here is full detail of my code: (i hope)
in my CXXXApp::InitInstance() i did:
<br />
m_pConnection.CreateInstance(__uuidof(Connection));
try<br />
{<br />
m_pConnection->Open<br />
("Provider=Microsoft.Jet.OLEDB.4.0;"<br />
"Data Source=D:\\DATA\\Nwind.mdb", "", "", -1);<br />
<br />
}<br />
catch(_com_error *e)<br />
{<br />
CString Error = e->ErrorMessage();<br />
AfxMessageBox(e->ErrorMessage());<br />
}<br />
catch(...)<br />
{<br />
<br />
}<br />
when i do this code in my View (it's MDI app) everything works fine.
when i do this - im getting into the catch(...).
is it making any sense to ya?
Avi.
|
|
|
|
|
Avi Laviad wrote:
when i do this - im getting into the catch(...).
What message is displayed?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
no message, i don't have anything in the "catch(...)".
how can i know the message?
(sorry for my , i guess, stupied questions, im a newbie)..
Avi.
|
|
|
|
|
My bad. I saw the one catch statement but not the other. I know of no way to ascertain the type/cause of exception at that point.
The last database application I did, the database object belonged to the document (as opposed to the app or the view). The document had methods for opening and closing the database connection.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Are you sure you called CoIninitialize(NULL) before CreateInstance call?
If you didn't call, you need to add that call before the CreateInstance and CoUninitialize() in ExitInstance function.
Jaime
|
|
|
|
|
well thanks you very very much jaime!!!
thank you all for your patient..
Avi
|
|
|
|
|
Some additional comments.
1.- Be sure CoInitialize is only called once in your application, and CoUninitialize is called just before shutting down the application.
2.- There was an easy way you could use to know which error occured. You know that CreateInstance returns an HRESULT. If after the call the pointer was 0x00000000, you can know the error by mean of the HRESULT (0 means no error).
For example, write the line this way:
HRESULT hr = ....CreateInstance(...);
or
TRACE("%x", ....CreateInstance(...));
Then copy the resulting code to the clipboard and finally, run the Error Lookup utility (present in Microsoft Visual Studio Tools menu). The copied error code will appear in Value edit box. Press Look Up button and the corresponding message will appear in Error Message window. For example, for your particular error, hr is 0x800401F0... using Error Lookup, you will get the message "CoInitialize has not been called".
Alternatively you can search that HRESULT code in winerror.h file.
Cheers
Jaime
|
|
|
|
|
wow!!
it's one of the help that i need to make as a Favourite Page.
10x man!
Avi.
|
|
|
|
|
Put a breakpoint on m_pConnection->Open line. Check to see if m_pConnection is not NULL and is valid.
If it isn't a _com_error it is more likely the pointer m_pConnection is invalid.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
i did it before and the pointer m_pConnection was NULL (0x00000000).
i do it in the InitInstance of the MainApp.
but if i do it in the View, everything is OK.
...
|
|
|
|
|
hi,
whats the name of the function that returns me the global application pointer?
|
|
|
|
|
If you are using MFC,
AfxGetApp() .
I Dream of Absolute Zero
|
|
|
|
|
I have 2 tree controls and when i drag an item form one tree control to another, the tree control doesnot get refreshed.
what should i do to avoid that
Manickavasagam N
Software Engg. Consultant
ISRO Satellite Centre
Bangalore
|
|
|
|
|
did you try
m_tree.Invalidate(TRUE);
it works fine with me.
|
|
|
|
|
I created a very simple dialog box with OK, CANCEL buttons on the top right hand corner of the dialog box. When I maximise the dialog box,these two buttons appear in the center of the dialog box. How can they be automatically positioned on the top right-hand corner of the enlarged window?
I am a beginner. Kindly help me out.
Srini
|
|
|
|
|
1. You add control variables for the buttons.
2. You add a handler for the dialog WM_SIZE .
3. In this function, you test for the buttons being created (as WM_SIZE will be sent before the controls are created), for example so:
if( m_okButton.m_hWnd )
{
4. If the buttons are created, you use the x and y inparameters to place and/or size the buttons as desired. The buttons can be moved with MoveWindow or SetWindowPos (the last one taking more parameters, but it can move without resize, for example).
|
|
|
|
|
Handle the WM_SIZING message (OnSizing() in MFC) and MoveWindow() your buttons according to the top-right corner.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I need to monitor oracle server connection through run time and close the application as soon as the connection to oracle server is lost.
Any suggestion would be appreciated?
Please also let me know if you have a good idea for the monitoring than creating a thread?
|
|
|
|
|
What oracle client version do you have? if it is 9xx.. have you installed OO4O?
Jaime
|
|
|
|
|
I have some data acqusition software in pc, This pc is acquireing data, I want send this data to another pc through USB. How I can Access USB driver?, What are the driver files? If some sample programme is there kindly send to me.
Regards,
subbu
|
|
|
|
|
USB wasn't designed for that, so you cannot do it without extra hardware. Best is to put an ethernet or 802.11 adaptor on USB, and use standard ip/sockets to comunicate.
Some companies make (or used to make) adaptors that would also do this. However I'm not sure extactly how they work, so I can't be sure they will provide you an interface to send data.
There is socket examples all over the internet, search them out.
|
|
|
|
|
hi,
I want to create only one instance of my application ,,
that only one instance run at a time on one PC.
any help or code plz
thanx
|
|
|
|
|
put a named mutex into the startup function...
|
|
|
|