DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Operation is not allowed on an object...

    [Originally posted by David]

    I'm trying to connect to a DB remotely and in my SQL Select statement I get the run time error:

    Operation is not allowed on an object referencing a closed or invalid connection.

    My code is below. What possible things could be causing this so I can start trouble shooting?

    I have DSN and ODBC connection setup on a win2000 machine.



    Public Sub cmdOK_Click()

    ÿ ÿ Set cnnGeneric = New ADODB.Connection

    ÿ ÿ cnnGeneric.Open "Provider=MS Remote;" _
    ÿ ÿ ÿ ÿ & "Remote Provider=MSDataShape;" _
    ÿ ÿ ÿ ÿ & "Remote Server=http://MyIpAdressHere;" _
    ÿ ÿ ÿ ÿ & "Data Source=MyDSNname;"

    ÿ ÿ ÿ ÿ Set rsGeneric = New ADODB.Recordset

    ÿ ÿ ÿ ÿ rsGeneric.CursorLocation = adUseClient
    ÿ ÿ ÿ ÿ rsGeneric.Open ("SELECT UserName, Password From tblUsers Where Username = '" & txtUserName.Text & "' AND Password = '" & txtPassword & "'")
    ÿ ÿ ÿ ÿ
    ÿ ÿ ÿ ÿ If rsGeneric.EOF Then
    ÿ ÿ ÿ ÿ ÿ ÿ MsgBox "Invalid Username or Password"
    ÿ ÿ ÿ ÿ ÿ ÿ rsGeneric.ActiveConnection = Nothing
    ÿ ÿ ÿ ÿ ÿ ÿ Exit Sub
    ÿ ÿ ÿ ÿ Else
    ÿ ÿ ÿ ÿ ÿ ÿ
    ÿ ÿ ÿ ÿ ÿ ÿ frmMain.Show
    ÿ ÿ ÿ ÿ ÿ ÿ Unload Me
    ÿ ÿ ÿ ÿ End If
    End Sub

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Operation is not allowed on an object...

    [Originally posted by FreeVBCode.com]

    You have to pass cnnGeneric as the 2nd argument to the open method of the recordset.

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Operation is not allowed on an object...

    [Originally posted by David]

    Whenever I do that I always get Expected "="

    Is it my syntax?

    rsGeneric.Open ("SELECT UserName, Password From tblUsers Where Username = '" & txtUserName.Text & "' AND Password = '" & txtPassword & "'",cnnGeneric)

  4. #4
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re:Operation is not allowed on an object...

    [Originally posted by FreeVBCode.com]

    Try getting rid of the parantheses.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links