You must use the dbSeeChanges option with OpenRecordset when accessing a sql server

johnkrytus

Registered User.
Local time
Today, 14:08
Joined
Mar 7, 2013
Messages
91
We just converted our database from postgres to SQL Server. This error appears to be all over our code.

You must use the dbSeeChanges option with OpenRecordset when accessing a sql server


I am only a novice level coder and the guy who often helps me just left on vacation. Any help would be appreciated greatly.

Apparently it dislikes this line of code:
Code:
Public Sub clearFilterForBucket(bucket_name As String, filter_id As Integer)
  CurrentDb.Execute ("delete from filter_actions where filter_id= " & filter_id & " AND action= '" & bucket_name & "'")
End Sub

Which is called from here:
Code:
Private Sub b_send_Click()
   Dim title_id As Integer
   Dim rstFilters As DAO.Recordset
   Dim rstPeople As DAO.Recordset
   Dim filterQry As String
   Dim answer As String
   Dim newFilter As DAO.Recordset
   Dim ctrl_bucket_name As String
   Dim maxSize As Integer
   maxSize = 100 '--how many records we can add to a filter at once
   
   If IsNull(ctrl_company_id) Then
     MsgBox ("You did not select a company")
   ElseIf IsNull(ctrl_company_titles) Then
     MsgBox ("You did not select a Title")
   ElseIf IsNull(ctrl_filtername) Then
     MsgBox ("You did not select a filter")
   Else
     Set rstPeople = [Forms]![Search_Filter_People]![filter_people_results].[Form].Recordset
     
     If rstPeople.RecordCount > maxSize Then
       MsgBox ("You are trying to add more than " & maxSize & " records to a filter. Please use a smaller data set")
     Else
       Call clearFilterForBucket("added", Forms.Search_Filter_People.Form.ctrl_filtername.Value)
       Call addPeopleToFilter(rstPeople, Forms.Search_Filter_People.Form.ctrl_filtername.Value)
     
       Me.filter_people_results.SourceObject = "filter_people_results"
       ctrl_bucket_name = "added"
     
       Me.filter_people_results.Form.RecordSource = "select (FirstName + ' ' + LastName) as fullname, * from people where EmployeeID IN ( select person_id from filter_actions where filter_id =" & ctrl_filtername & " and action='" & ctrl_bucket_name & "') order by LastCnct desc"
       Me.filter_people_results.Form.Requery
       update_bucketcounts
     End If
   End If
End Sub
 
This is that rare error that tells you exactly what is wrong.

Db.Execute "delete from filter_actions where filter_id= " & filter_id & " AND action= '" & bucket_name & "'", dbSeeChanges
 
generally this. (there might be an extra comma before the dbseechanges)

db.openrecordset("somequery"),dbseechanges
 
For a recordset:

Set rs = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
 
thanks paul - often hard to do things you rarely do from memory.

john - you will need to convert every usage of recordsets in your app to use dbseechanges. bit of a pain.
 
If memory serves, it's actually only necessary if the SQL Server table has an Identity (autonumber) field. It doesn't hurt to have it everywhere though, in case the source changes (as happened here).
 
This is an "invalid operation"

From what I understand of this it's not what I want to do anyways... I just want the query to run. I don't want to assign a value to rs. ....do I???? Sorry. I know I'm in over my head here, but that doesnt get me off the hook for needing to solve it.

Code:
Public Sub clearFilterForBucket(bucket_name As String, filter_id As Integer)
  Dim rs As DAO.Recordset
  Set rs = CurrentDb.OpenRecordset("delete from filter_actions where filter_id= " & filter_id & " AND action= '" & bucket_name & "'", dbOpenDynaset, dbSeeChanges)
End Sub
 
Did you try what I posted in post 2?
 
Did you change back to CurrentDb? Somehow in my copying and pasting that got changed. should be:

CurrentDb.Execute "delete from filter_actions where filter_id= " & filter_id & " AND action= '" & bucket_name & "'", dbSeeChanges

I use a variable for the SQL, but it should work either way. This is from a production db:

CurrentDb.Execute strSQL, dbSeeChanges
 
It works!! I don't know what I'd do without this forum! You guys rock!

Code:
Public Sub clearFilterForBucket(bucket_name As String, filter_id As Integer)
  Currentdb.Execute "delete from filter_actions where filter_id= " & filter_id & " AND action= '" & bucket_name & "'", dbSeeChanges
End Sub
 
as an aside, now you mention the issue of identity columns ...

I have been really struggling with SQL server, trying to insert data to tables with autonumber fields. I "set identity insert" on, but the pass through query won't take it off again.

I think perhaps you have to use a different connection to take it off. Total pain. What I am having to do, is exit and restart access, and then the next "set identity insert" works
 
I "set identity insert" on, but the pass through query won't take it off again.

SET IDENTITY_INSERT tablenameWithIdentitySetOn OFF is the correct syntax, I'm intrigued as to why you would be inserting values into an identity field.
 
SET IDENTITY_INSERT tablenameWithIdentitySetOn OFF is the correct syntax, I'm intrigued as to why you would be inserting values into an identity field.

I'm upsizing an access dbs to Sql server. Some tables have autonumbers and I can't use any wizard. I have to do it a table at a time.
 

Users who are viewing this thread

Back
Top Bottom