CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2006
    Location
    Athens, Greece
    Posts
    111

    Unhappy 3219_Operation is not allowed in this context

    hello gurus!!!

    i have the code below
    Code:
    Private Sub OpenKostosTherpion()
        On Error GoTo ErrorHandler
        
        Dim tmpCommand As ADODB.Command
        Set rsKostosTherapion = New ADODB.Recordset
        Set tmpCommand = New ADODB.Command
        Dim strSQL As String
        
        strSQL = CSTR_SYNOLIKO_KOSTOS_THERAPION & intCustID
        
        With tmpCommand
            Set .ActiveConnection = VPConnection
            .CommandType = adCmdText
            .CommandText = strSQL
            .Execute
        End With
        
        With rsKostosTherapion
            .CursorLocation = adUseClient
            Call .Open(tmpCommand, , adOpenKeyset, adLockOptimistic)
            
            boolrsKostosTherapion = True
            
            Set dgKostosTherapion.DataSource = rsKostosTherapion
            
            Call WriteToLog("Sub SetDataToScreen Started", "Plain")
            Call SetDataToScreen
            Call WriteToLog("Sub SetDataToScreen Terminated", "Plain")
        End With
        
    ErrorHandler:
        If Err <> 0 Then
            strErrorus = P_strSQL
            Call LogError(Err, "frmCustomers.OpenKostosTherpion")
            strErrorus = ""
        Else
            Exit Sub
        End If
    End Sub
    
    Private Sub SetDataToScreen()
        On Error GoTo ErrorHandler
            
        With dgKostosTherapion
            .Columns(0).Value = rsKostosTherapion.Fields("therapy_category_desc").Value
            .Columns(1).Value = rsKostosTherapion.Fields("therapia_desc").Value
            .Columns(2).Value = rsKostosTherapion.Fields("therapia_progress").Value
            .Columns(3).Value = rsKostosTherapion.Fields("therapia_date_start").Value
            .Columns(4).Value = rsKostosTherapion.Fields("therapia_default_kostos").Value
            .Columns(5).Value = rsKostosTherapion.Fields("therapia_teliko_kostos").Value
        End With
        
    ErrorHandler:
        If Err <> 0 Then
            Call LogError(Err, "frmCustomers.OpenKostosTherpion")
        Else
            Exit Sub
        End If
    End Sub
    and when i'm trying to close the recordset with the code below,
    Code:
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        On Error GoTo ErrorHandler
        
        mdimain.mnunewcustomer.Checked = False
        mdimain.mnushowcustomers.Checked = False
        
         If boolrsKostosTherapion = True Then
            
            
            dgKostosTherapion.ClearFields
            Set dgKostosTherapion.DataSource = Nothing
           
            rsKostosTherapion.Close
            Set rsKostosTherapion = Nothing
            
        End If
        
    ErrorHandler:
        If Err <> 0 Then
            Call LogError(Err, "frmCustomers.Form_Unload")
        Else
            Exit Sub
        End If
    End Sub
    i'm recieving this error message
    3219|ADODB.Recordset|Operation is not allowed in this context.|frmCustomers.Form_Unload|"

    The database is MSACCESS 2003
    The Connection String is...
    Code:
    Public Const CSTR_CONNECTION = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db.mdb;Persist Security Info=False;Jet OLEDB:Database Password=xxxxx"
    The only thing that i'm doing with the datagrid, is to represent the data not update or insert anything

    Thanks,
    Regards,
    VPlag
    Last edited by vplag; November 2nd, 2006 at 03:37 AM.
    Good Luck
    -------------------*-------------------*------------------------
    Today we will see how we can develop:

    Ingredients:

    Espresso, cigarettes and lounge music
    -----------------------------------------------------------------
    Please remember to rate the posts and threads that you find useful

  2. #2
    Join Date
    Sep 2006
    Posts
    635

    Re: 3219_Operation is not allowed in this context

    I think your msg error is for:

    Code:
    dgKostosTherapion.ClearFields
    with this only :

    Code:
     If boolrsKostosTherapion = True Then
    		Set rsKostosTherapion = Nothing
    		Set dgKostosTherapion.DataSource = Nothing	    
    	End If

  3. #3
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: 3219_Operation is not allowed in this context

    Use debug and go through code line by lien and look in which command the error comes up. I thing hensa22 is right and it will be the clearfields command. what do you want to get with that command as a result ? Closing recordset and setting it to nothig should be enough.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  4. #4
    Join Date
    Feb 2006
    Location
    Athens, Greece
    Posts
    111

    Unhappy Re: 3219_Operation is not allowed in this context

    Quote Originally Posted by JonnyPoet
    Use debug and go through code line by lien and look in which command the error comes up. I thing hensa22 is right and it will be the clearfields command. what do you want to get with that command as a result ? Closing recordset and setting it to nothig should be enough.
    I made the change that u wote me.
    I've removed the Clearfields and i left only the .close and set to nothing commands.
    Now i'm recieving this message
    Code:
    Insufficient key column information for updating or refreshing
    Using the debuger, the error comes by the closing of the recordset
    Also the only thing that i'm doing, is to represent data (ONLY) and when the user close the form, to close also the recordset....

    The wierd thing is that if i fill the datagrid with an ado control, i'don't recieve any error message....

    Thanks,
    Regards,
    VPlag
    Last edited by vplag; November 6th, 2006 at 05:38 AM.
    Good Luck
    -------------------*-------------------*------------------------
    Today we will see how we can develop:

    Ingredients:

    Espresso, cigarettes and lounge music
    -----------------------------------------------------------------
    Please remember to rate the posts and threads that you find useful

  5. #5
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: 3219_Operation is not allowed in this context

    The wierd thing is that if i fill the datagrid with an ado control, i'don't recieve any error message....
    Upps.. Whatelse are u using. Datgrid in its last version is usable for ADO Datacontrols and DE ( Dataenviroment objects ) but as I know only some old versions ( VB 5.0 or earlier) work with DAO 3.51 und DAO 3.6
    If you need to use it with DAO 3.6 then dont use datasource and all that but instead ( sorry, some work ) fill it by handwritten code field by field. Thats as it is. I think.
    If you wannt to use ADODB togther with the grid ( without a datacontrol ) then ( I havn't tried this before ) I assume the recordset maybe needs to be disconnected before closing and before closing the form where the grid is and before closing the recordset.
    Last edited by JonnyPoet; November 6th, 2006 at 07:31 AM.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  6. #6
    Join Date
    Feb 2006
    Location
    Athens, Greece
    Posts
    111

    Red face Re: 3219_Operation is not allowed in this context

    Quote Originally Posted by JonnyPoet
    Upps.. Whatelse are u using. Datgrid in its last version is usable for ADO Datacontrols and DE ( Dataenviroment objects ) but as I know only some old versions ( VB 5.0 or earlier) work with DAO 3.51 und DAO 3.6
    If you need to use it with DAO 3.6 then dont use datasource and all that but instead ( sorry, some work ) fill it by handwritten code field by field. Thats as it is. I think.
    If you wannt to use ADODB togther with the grid ( without a datacontrol ) then ( I havn't tried this before ) I assume the recordset maybe needs to be disconnected before closing and before closing the form where the grid is and before closing the recordset.
    First of all, thanks for your reply!!!!
    Before .close i've wrote
    Code:
    rsKostosTherapion.CancelBatch
    and i haven't since then any problem.

    I've to admit that ths was very very wierd because i 've done the same in the past but the database was MSSQL and it was working normally without problems.

    Anyway thaks a lot!!!

    Regards,
    VPlag
    Good Luck
    -------------------*-------------------*------------------------
    Today we will see how we can develop:

    Ingredients:

    Espresso, cigarettes and lounge music
    -----------------------------------------------------------------
    Please remember to rate the posts and threads that you find useful

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

Featured