Creating new object b/n

Results 1 to 2 of 2

Thread: Creating new object b/n

  1. #1
    Join Date
    Dec 1969

    Default Creating new object b/n

    I have a number components on our server and recently decided to create another component which contains a Connection object. The idea is that I will initialise and create the connection object from within one of the existing components. The object returns a handle of type ADODB.Connection, from which I use to connect to our SQL Server.<BR><BR>The problem is that it doesn&#039;t work! I get the error &#039;Cannot create automation object&#039;.<BR><BR>I can create the Connection object by itself but not from inside another component. What is going on? I have limited experience in COM+.<BR><BR>Thanks in advance.<BR><BR>Here is my code....<BR><BR>Component A<BR>Class A<BR><BR>Private gCon As ADODB.Connection<BR><BR>Private Sub Class_Initialize()<BR> &#039;Create connection object and return a connection<BR> Dim Connect As New MCConnection.Connection<BR> <BR> Set gCon = Connect.CreateConnection() <BR>End Sub<BR><BR><BR><BR>Component B<BR>Class Connection<BR><BR>Public Con As New ADODB.Connection<BR><BR>Public Function CreateConnection() As ADODB.Connection<BR> <BR> &#039;Connect to SQL Server<BR> With Con<BR> .ConnectionTimeout = 10<BR> <BR> <BR> &#039;Assign connection string<BR> .ConnectionString = blah<BR> .CursorLocation = adUseClient<BR> <BR> End With<BR> <BR> Con.Open<BR> <BR> If Con.State = adStateOpen Then<BR> <BR> Set CreateConnection = Con<BR> <BR> Else<BR> Set CreateConnection = Nothing<BR> <BR> End If<BR>End Function<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Creating new object b/n

    Not 100% sure but in Component B change Set CreateConnection = Con to CreateConnection = Con. I don&#039;t think you need the Set statement there to return the variable to the calling object. However, even if that does work I would make the following suggestion- you should make Component B deal with all your interaction with the database. Let it manage querying/updating the database instead of all the other objects. I just responded to another message titled "Query" read for a more thorough explaination. Hope this helps. THX

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts