Results 1 to 4 of 4

Thread: Error! "operation is not allowed,when the object is closed"

  1. #1

    Thread Starter
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    Error! "operation is not allowed,when the object is closed"

    I installed SQL Server and wrote my StoredProcedures in SQL, then wrote
    below commands for connection to database in VB6.0:
    VB Code:
    1. Set Cnn = New ADODB.Connection
    2. Set Rss = New ADODB.Recordset
    3. Set cmd = New ADODB.Command
    4. Cnn.ConnectionString = provider
    5. Cnn.Open
    6. cmd.ActiveConnection = Cnn
    7. cmd.CommandText = "CounterDoc_View" 'storedprocedurd name!
    8.  
    9. cmd.Parameters.Append cmd.CreateParameter("@DocID", adInteger,
    10. adParamInput, 4, id)
    11. cmd.Parameters.Append cmd.CreateParameter("@UserLanguage", adChar,
    12. adParamInput, 2, UserLanguage)
    13. cmd.Parameters.Append cmd.CreateParameter("@LoginName", adVarChar,
    14. adParamInput, 50, Loginname)
    15.  
    16. cmd.CommandType = adCmdStoredProc
    17. cmd.CommandTimeout = 0
    18. cmd.Prepared = True
    19. Set Rss = cmd.Execute
    and my StoredProcedure is:

    Code:
    CREATE PROCEDURE CounterDoc_View
    
    @DocID int,
    @UserLanguage char(2),
    @LoginName nvarchar(50)
    
    as
    Declare    @TemSqlStr as varchar(4000)
    
    Set @TemSqlStr='Select LoginName, Name, Family, ID '
    
    if (@UserLanguage='En')
           Set @TemSqlStr=@TemSqlStr+', FirstAccessDate, LastAccessDate '
    else
           Set @TemSqlStr=@TemSqlStr+' ,dbo.Jal2Ch(FirstAccessDate) as
    FirstAccessDate, dbo.Jal2Ch(LastAccessDate) as LastAccessDate  '
    
    Set @TemSqlStr=@TemSqlStr+' From View_DocCounter where ID<>0  '
    Set @TemSqlStr=@TemSqlStr+' and (ID ='+Convert(varchar(5), @DocID)+') '
    
    if ((@LoginName!='') and (@LoginName!='Empty') and (@LoginName is not
    Null))
      Set @TemSqlStr=@TemSqlStr+' and LoginName='''+@LoginName+''''
    
    Exec (@TemSqlStr)
    Go
    after execution of my program in VB6.0 on this command "If Not Rss.EOF
    Then" (and when program wants retrieve resuls of execution of SP)below
    error will be appear:
    "operation is not allowed,when the object is closed"

    Thanks for your attention to me.
    Regards!

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Error! "operation is not allowed,when the object is closed"

    If you step through your code by pressing F8, does your Cnn.Open
    open without error? Do you have any "On Error Resume Next" statements?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    New Member
    Join Date
    Feb 2010
    Posts
    1

    Re: Error! "operation is not allowed,when the object is closed"

    I had the same problem. I found that the VBA recordset wouldn't open for my SP but it did for all the others.
    I simply added "SET NOCOUNT ON" after the "AS" at the top of the SP and that fixed it. Recordset opens every time
    It took an hour of puzzling before I found this out.

  4. #4
    New Member
    Join Date
    May 2011
    Posts
    1

    Smile Re: Error! "operation is not allowed,when the object is closed"

    Quote Originally Posted by TonyDataMan View Post
    I had the same problem. I found that the VBA recordset wouldn't open for my SP but it did for all the others.
    I simply added "SET NOCOUNT ON" after the "AS" at the top of the SP and that fixed it. Recordset opens every time
    It took an hour of puzzling before I found this out.
    Thanks This is usefull for me

Posting Permissions

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



Click Here to Expand Forum to Full Width