We help IT Professionals succeed at work.

Problem using VB COM objects...

vt45 asked
I have a COM object written with VB within an ActiveX DLL.  This object works fine when referenced by a VB app.  I'd like to use that same object in a new ASP project I'm working on.  I've registered the DLL on the server.  I've debugged(by way of App.LogEvent) the whole function I'm having problems with.  It interacts with another SQLServer box, log's the user on and sets permissions, creating the connection.  The function has error handling and for some reason it raises an error apparently after the Exit Function statement.  Here is the error:

err.desc =  [DBNETLIB][ConnectionRead (recv()).]General network error. Check your network documentation.
err.number = -2147467259

I haven't been able to find any documentation on this particular error.  Does anyone have any suggestions as to what my be going on here? Do I have some bad IIS 5.0 settings?  Could it be SQLServer 7?  I'll provide the code below.  Thanks.

Sub ConnectDB()
Dim b
      Set objCon = Server.CreateObject("ADODB.Connection")
      Set logon = Server.CreateObject("xxxxxxSecure.cLogon")
      logon.AppProductName = "RealSimple"
      logon.Version = "1.0.0"
      Set logon.Connection = objCon
      logon.Environment = 2
      logon.UserName = "xxxxxxx"
      logon.Password = "xxxxx"
      b = logon.Logon
End Sub
---end index.asp---

--cLogon class mod--
Public Function Logon() As Boolean
    Dim rs As ADODB.Recordset
    Dim sql As String
    On Error GoTo LocalError

    'Determine if the logon is coming from the Logon Form.
    'If so, notify user that Logon process is executing
    If Not mfrmLogin Is Nothing Then
        mfrmLogin.MousePointer = vbHourglass
        mfrmLogin.UpdateStatus "Please wait..."
    End If

    Logon = False

    'Validate the users credentials
    If mUserName = "" Then
        MsgBox "You must specify a UserName"
        Exit Function
    End If

    If mPassword = "" Then
        MsgBox "You must enter a Password"
        Exit Function
    End If

If Not mfrmLogin Is Nothing Then mfrmLogin.UpdateStatus "Logging into Database..."

    'Set the DB connection properties and attempt to open the connection
    With mvarConnection
        .Provider = "sqloledb"
        .CursorLocation = adUseClient
        .Properties("user id") = mUserName
        .Properties("password") = mPassword
        .Properties("data source") = ResolveDBName(mEnvironment)
        .Properties("initial catalog") = "security"
        .Properties("network library") = "DBNETLIB"
    End With

    'If the connection is open, the logon succeeded
    If mvarConnection.State = adStateOpen Then
        Logon = True
    End If

    'Determine if the user needs to change their password due to an initial logon
    If LCase(mPassword) = "password" Or LCase(mPassword) = LCase(mUserName) Then
        MsgBox "You must change your password before continuing", vbOKCancel + vbExclamation, "Change Password"
        mfrmLogin.chkChange.Value = 0
        If Not ChangePassword Then
            Logon = False
            Exit Function
        End If

    End If

    'Determinie if the user requested to change their password
    If Not mfrmLogin Is Nothing Then
        If mfrmLogin.chkChange Then
            If Not ChangePassword Then
                Logon = False
                Exit Function
            End If
        End If
    End If
If Not mfrmLogin Is Nothing Then mfrmLogin.UpdateStatus "Verifying access to application..."
    'Validate the user against the security database.  Although the use was granted access to the
    'Database, they may not have access to the application.
    Set rs = CreateRecordset
    Set rs = mvarConnection.Execute("security..validate_user " & _
        "@user_id = '" & mUserName & "' " & _
            ",@application_name = '" & mAppProductName & "' " & _
                ",@version = '" & mVersion & "' ")

    'Set the connection database
    If mAppProductName = "Security" Then
        mvarConnection.Execute "use security"
        mvarConnection.Execute "use admin"
    End If

If Not mfrmLogin Is Nothing Then mfrmLogin.UpdateStatus "Granting Application Permissions..."
    'Set the application role for the current user.  This will grant the user
    'permissions.  Without doing this, the user will have no permissions in the databse.
    sql = "DECLARE @pass varbinary(256)" & _
        " SET @pass = {Encrypt N '" & rs!role_password & "'}" & _
            " exec sp_setapprole " & _
                "@rolename = '" & rs!role_name & "'" & _
                    ",@password = @pass " & _
                        ",@encrypt = 'odbc'"
    mvarConnection.Execute sql
If Not mfrmLogin Is Nothing Then mfrmLogin.UpdateStatus "Gathering object permissions..."
    'Load the user and application object
    mUser.Load mUserName, Me
    mApplication.Load rs!application_id, Me
    'Retrieve the users Profiles and LogonPermissions.  This will allow applications to
    'Determine was application objects the user is allowed to interact with.
    Set mLogonProfiles = LogonProfiles
    Set mLogonPermissions = LogonPermissions

    Set rs = Nothing
    'Save the database the user logged into for their next connection
    SaveSetting mAppProductName, "Settings", "DataBase", mEnvironment
    'Method complete.  Notify user
    If Not mfrmLogin Is Nothing Then mfrmLogin.UpdateStatus "Login Succeeded..."
    Set gLogon = Me
    If Not mfrmLogin Is Nothing Then mfrmLogin.MousePointer = vbDefault
Exit Function
    If Not mfrmLogin Is Nothing Then mfrmLogin.UpdateStatus "Login Failed.  Please Try Again."
    App.LogEvent Err.Description & ":" & Err.Number, 1
    LogError "Logon", Err
    Logon = False
    mfrmLogin.MousePointer = vbDefault
End Function
--end cLogon--
---end xxxxxxSecure.dll---

-I'm not creating mfrmLogin for my ASP project, so it is nothing.
-I've set up debug's at each line and have confirmed that it is making it all the way to Exit Function before it raises the error.
Watch Question

Take of all the MSgbox functions from the VB component. ASP runs on server side. It does not understand MSgbox. Instead pass the value back to the calling asp page.

Something like this

 If mUserName = "" Then
       Return False
       Exit Function
   End If

and in ASP page you can always check the boolean value and do appropriate actions.
Are you saying that you are successfully able to read information from the database to validate the security but it still throws up this connection error ??

One thing to note is that it does not look like you are using TCP/IP as the net library which might be a problem, you may want to try changing:

.Properties("network library") = "DBNETLIB"


.Properties("network library") = "dbmssocn"

for TCP/IP access.

Also you better get rid of all those MsgBoxes, this will cause you much problem when you try to run under ASP.


Dave Kawliche


Thanks guys for the help.  I removed all my msgboxes, and changed my network library to DBMSSOCN, which I think is the same as DBNETLIB.  Still wouldn't work.  So I decieded to disable error handling and now I have a much bigger problem:

ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
POINTS FOR EXPERTS awaiting comments are listed in the link below
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moderator @ Experts Exchange
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **

Explore More ContentExplore courses, solutions, and other research materials related to this topic.