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!

COM Connection object

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
Here is my problem, I've got an object that I am initializing at the beginning of my program:

ShipPostageConn.CreateInstance(__uuidof(Connection));

This connnection is going to be going to be closed and opened many times to different databases...I think this is my problem. After I get done with one database and I want to close it, it closes okay, but once it goes out of my function, it gives an Access error. I think it's having a hard time freeing this pointer. It doesn't error in any of my code but in the libraries that MFC uses. Something else that was really weird was I had a combo box and I tried to make it "enabled"...it would work okay before I sent my SQL statement across the command pointer, but if I tried to "enable" my combobox AFTER I sent my SQL statment, my app would give an access violation. The reason I know that it is this particular pointer is because I have another similar pointer that stays connected through the whole program and I don't have any problem with it. The program gives the access error after I have connected to the Database and exit out of my function using the ShipPostageConn pointer. Is there some way that I can set that object to NULL? Something like:

ShipPostageConn.CreateInstance(NULL);

so that I can free it up? Any and all help is greatly appreciated. I probably sound a bit muddled right now, that's cause I've been working on this thing all day and my mind is mush...I'm sure ya'll understand that.

Niky Williams
NTS Marketing
 
Niky,

Your verbal description of the flow of control and variable scopes is not easy to follow. If you can provide a clearer description I might be able to help.

-pete
 
Sorry, yesterday my mind was just so drained. Since I've gotten some sleep, maybe I can make more sense.

I have one connection pointer called ShipPostageConn. This pointer is initialized in the beginning of my program like so:

ShipPostageConn.CreateInstance(__uuidof(Connection));

In the flow of my program, the user chooses certain options. These options are the determining factor to what SQL database my connection pointer is attached to. After I get done with that part of my program, I close out the database so that I can use that connection pointer again on a different database. The reason I'm using the same connection pointer is because I don't want to have 5 or 6 seperate connection pointers connected at the same time to our SQL server. I think the problem is that after the connection is opened to the SQL database and the user gets done doing what he/she needs to do and I close it, the program is having a hard time deallocating the connection pointer and this is what is causing the Access Violaion. The connection seems to close just fine, but right after I step out of my function is when it throws the access violation. Now, the other weird thing I was talking about is I have a ComboBox with member function m_ship. Right before I open my ShipPostageConn, I execute this:

m_ship.EnableWindow(false);

That works just fine. If after I open my ShipPostageConn and execute a direct SQL statment using a command pointer I try the code:

m_ship.EnableWindow(false);

it throws an access violation. What the heck?

So I know for SURE that there is something wrong with my ShipPostageConn pointer or my _ShipPostageCmd pointer (Command pointer that uses ShipPostageConn as the active connection). My guess is that something just is not getting deallocated correctly.

I do have another connection pointer called LegendConn that I have initialized at the beginning of my program, after the program is done, I close this connection. I have NO problems with this pointer. The only difference between these two pointers is that ShipPostageConn is opened and closed multiple times and LegendConn is opened once and closed once. As long as the flow of my program does not go to the function that opens the ShipPostageConn, my program runs fine. This is just really wierd, I'm tryint some different things that I thought of last night, but if you have any insight or info, I would greatly appreciate it. I realize it's difficult to debug a program when you really haven't seen it, but thanks again for your time.

Niky Williams
NTS Marketing
 
Something else that is really weird is that after I close my connection to the database, exit my function and it throws the Access violations it is changing a field in my SQL table!! How the heck can it do that AFTER I have closed my connection? To me this would mean that the connection never actually closed and the pointer reference never got deallocated. Am I barking up the wrong tree or does this sound like it may be true? I was also thinking that my SQL statement that I am executing may have something to do with it....not sure yet, still checking into it...could somehow passing a value of the wrong type in my SQL string be causing this? It is only one field that I'm getting funky values in. Thanks for any info!

Niky Williams
NTS Marketing
 
Okay, this is even weirder...it had nothing to do with what I talked about earlier. I took out some code, rewrote some stuff...now my program works great. ACK I don't know what happened exactly. Thanks for anyone who has responded or thought about responding to my questions.

Niky Williams
NTS Marketing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top