Link to home
Start Free TrialLog in
Avatar of Joeharvey
Joeharvey

asked on

COM+ question

I have a ActiveX dll installed on a remote server which I am using to connect to SQL Server and access data, passing back to a client app.  When the dll calls the connect function, it appears that it is still the client machine that is connecting to SQL Server, not the dll.  How do I configure it so the transaction server/COM+ server handles the connection and data access rather than the client PC?
Avatar of rpai
rpai

Your client app would be instanciating the Activex DLL which in would establish the connection to the Server. The client would use the type library or custom proxy-stub DLL on the client to use your server application remotely.
Avatar of Joeharvey

ASKER

I'm not sure what you mean.  What needs to be done in order for the server(middle-tier) to make the actual database connection and return the result set to the client?  Or is this not possible?
Well, a couple of things.  First, your COM+ component should be handling all of the ADO calls to open the connection and recordsets etc.  I'd suggest that each method call to the component calls to open the connection and then closes the connection on the way out.  This may sound like a lot of overhead, but I think that connection pooling keeps the overhead down.  On the plus side, it forces you to design Stateless components which is much better for scaleability.

Your code should look pretty normal in the COM+ component.

In the Client, you should be sure to use CreateObject to instantiate your middle-tier component.  I think if you use New, then this invokes the COM interface and not the COM+ interface.  So, if you have a local version of the DLL (which is likely if you are working on your development machine), using New will run the local DLL as opposed to the remote one.

Last thought, you should try not to pass a recordset as in input parm to your middle-tier component.  Passing recordsets across processes has a huge overhead, and, what happens is that the COM+ component really just gets a copy of the recordset anyway (and it's not really a complete copy of the recordset, just the data without all of the property settings of things like .RecordCount, .Filter etc.)

You can return a recordset as the return value of a function, and your client should be able to use it correctly, but this is still somewhat inefficient.  We used to convert the recordset to XML using the Recordset Save option into a Microsoft DOM object, and then would send the DOM object's XML back to the client.  This was very fast.  Then, on the client, you can reload the XML into a recordset if you want, or load it into a DOM and use that to process the data.....
mdougan,

  I was creating the component on the client using NEW.  I will try using the CreateObject and let you know what happens.  Thanks for the info.
After installing the DLL on the server, and distributing it to a client pc, I used CreateObject to instantiate the component.  It is still creating the connection from the client pc.  Is there something inside of the dll that I am missing here?  No matter what I try I still get the connection coming from the client.
I believe the only place you have the code to establish a Database connection is in the DLL component. Is that right?

Now the way COM+ works is, whenever the client app instanciates the Remote DLL (using CreateObject), there is a proxy object (of the DLL on the remote server) created on the client machine. The client would use the type library or custom proxy-stub DLL on the client to establish the DB Connection. (You can imagine as a image of the DLL object being created on the client machine). My guess is, that is the reason why it appears as if the connection is being made by the client.
You are correct rpai.  The only code to make the db connection is in the class.  (Connecting to a SQL Server database).

When I launch the client app, I can go into SQL Server and look at the current connections.  When doing so, I see that the connection (Host name) is coming from the client pc.  


ASKER CERTIFIED SOLUTION
Avatar of rpai
rpai

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial