Results 1 to 15 of 15
  1. #1
    Vita's Avatar
    Vita is offline Competent Performer
    Windows 10 Access 2002
    Join Date
    May 2022
    Location
    Massachusetts, USA
    Posts
    296

    Preventing database from being placed in a state that prevents it from being opened or locked?


    I have been working on a database/tool to open tables from a sql server and modify them but I need it to be opened on more than 1 computer at a time. Several people will be using it at the same time.
    I keep getting this error when I try to open up a second instance on a separate pc.
    "The database has be placed in a state by user 'name' on machine 'name' that prevents it from being opened or locked."

    I checked the options and open mode is set to shared and record locking is set to no locks.
    Can anyone help me fix this? I am aware I might have just designed everything wrong from the start but I am hoping there is a fix.

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    When you say
    open tables from a sql server and modify them
    do you actually mean opening the (linked) table or running DDL SQL pass-through queries to modify the tables (that is how I would do it). Here is an example how to change bit fields in SQL to not accept NULL and set the default to 0 (to avoid the write conflict error):
    Code:
    Public Function vcCheckBoxesSetDefaultZero()
    
    Dim tdf As DAO.TableDef, db As DAO.Database, fld As Field
    Dim sTable As String, sField As String
    
    
    Set db = CurrentDb
    
    
    For Each tdf In db.TableDefs
    
    
        If Left(tdf.Name, 4) <> "msys" Then
        
            'only do SQL Server tables
            If InStr(tdf.Connect, "SQL Server") > 0 Then
                For Each fld In tdf.Fields
        
                    If fld.Type = dbBoolean Then
                    sTable = tdf.Name
                    sField = fld.Name
                    'call update to replace nulls with zeroes
                    Call vcAlterTable(tdf.Name, "UPDATE [" & sTable & "] SET [" & sField & "] = " & 0 & " WHERE [" & sField & "] IS NULL;", "tblAgents")
                    'now lets alter the table
                    Call vcAlterTable(tdf.Name, "ALTER TABLE [" & sTable & "] ALTER COLUMN [" & sField & "] BIT NOT NULL", "tblAgents")
                    Call vcAlterTable(tdf.Name, "ALTER TABLE [" & sTable & "] ADD CONSTRAINT DF_" & sTable & "_" & sField & " DEFAULT 0 FOR " & sField & ";", "tblAgents")
                    'Call vcAlterTable(tdf.Name, "ALTER TABLE [" & sTable & "] ALTER COLUMN [" & sField & "] BIT NOT NULL ;", "NAMES")
        
                    End If
        
                Next fld
            End If
        End If
    
    
    Next tdf
    
    
       MsgBox "DONE"
    
    
    
    
    End Function
    Public Function vcAlterTable(strSourceTable As String, sAlterSQL As String, sUseConnectionStringFrom As String)
    Dim db As DAO.Database
    Dim qdExtData As QueryDef
    Dim strSQL As String
    
    
    On Error Resume Next
    
    
    Set db = CurrentDb
    If ObjectExists("QUERY", "sqlALTER_TABLE") Then DoCmd.DeleteObject acQuery, "sqlALTER_TABLE"
    strSQL = sAlterSQL
    Set qdExtData = db.CreateQueryDef("sqlALTER_TABLE")
    
    
    qdExtData.Connect = CurrentDb.TableDefs(sUseConnectionStringFrom).Connect
    qdExtData.ReturnsRecords = False
    qdExtData.SQL = strSQL
    
    
    CurrentDb.QueryDefs("sqlALTER_TABLE").Execute
    
    
    'lets refresh the link
    CurrentDb.TableDefs(strSourceTable).RefreshLink
    
    
    qdExtData.Close
    db.Close
    Set db = Nothing
    'MsgBox "ALTER TABLE STATEMENT COMPLETED - PLEASE CHECK THE TABLE IN DESIGN VIEW"
    End Function
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Join Date
    Apr 2017
    Posts
    1,792
    Are your users trying all to use the same Access front-end, or do they have their own copies of it?

  4. #4
    Vita's Avatar
    Vita is offline Competent Performer
    Windows 10 Access 2002
    Join Date
    May 2022
    Location
    Massachusetts, USA
    Posts
    296
    Quote Originally Posted by Gicu View Post
    When you say do you actually mean opening the (linked) table or running DDL SQL pass-through queries to modify the tables (that is how I would do it). Here is an example how to change bit fields in SQL to not accept NULL and set the default to 0 (to avoid the write conflict error):
    Code:
    Public Function vcCheckBoxesSetDefaultZero()
    
    Dim tdf As DAO.TableDef, db As DAO.Database, fld As Field
    Dim sTable As String, sField As String
    
    
    Set db = CurrentDb
    
    
    For Each tdf In db.TableDefs
    
    
        If Left(tdf.Name, 4) <> "msys" Then
        
            'only do SQL Server tables
            If InStr(tdf.Connect, "SQL Server") > 0 Then
                For Each fld In tdf.Fields
        
                    If fld.Type = dbBoolean Then
                    sTable = tdf.Name
                    sField = fld.Name
                    'call update to replace nulls with zeroes
                    Call vcAlterTable(tdf.Name, "UPDATE [" & sTable & "] SET [" & sField & "] = " & 0 & " WHERE [" & sField & "] IS NULL;", "tblAgents")
                    'now lets alter the table
                    Call vcAlterTable(tdf.Name, "ALTER TABLE [" & sTable & "] ALTER COLUMN [" & sField & "] BIT NOT NULL", "tblAgents")
                    Call vcAlterTable(tdf.Name, "ALTER TABLE [" & sTable & "] ADD CONSTRAINT DF_" & sTable & "_" & sField & " DEFAULT 0 FOR " & sField & ";", "tblAgents")
                    'Call vcAlterTable(tdf.Name, "ALTER TABLE [" & sTable & "] ALTER COLUMN [" & sField & "] BIT NOT NULL ;", "NAMES")
        
                    End If
        
                Next fld
            End If
        End If
    
    
    Next tdf
    
    
       MsgBox "DONE"
    
    
    
    
    End Function
    Public Function vcAlterTable(strSourceTable As String, sAlterSQL As String, sUseConnectionStringFrom As String)
    Dim db As DAO.Database
    Dim qdExtData As QueryDef
    Dim strSQL As String
    
    
    On Error Resume Next
    
    
    Set db = CurrentDb
    If ObjectExists("QUERY", "sqlALTER_TABLE") Then DoCmd.DeleteObject acQuery, "sqlALTER_TABLE"
    strSQL = sAlterSQL
    Set qdExtData = db.CreateQueryDef("sqlALTER_TABLE")
    
    
    qdExtData.Connect = CurrentDb.TableDefs(sUseConnectionStringFrom).Connect
    qdExtData.ReturnsRecords = False
    qdExtData.SQL = strSQL
    
    
    CurrentDb.QueryDefs("sqlALTER_TABLE").Execute
    
    
    'lets refresh the link
    CurrentDb.TableDefs(strSourceTable).RefreshLink
    
    
    qdExtData.Close
    db.Close
    Set db = Nothing
    'MsgBox "ALTER TABLE STATEMENT COMPLETED - PLEASE CHECK THE TABLE IN DESIGN VIEW"
    End Function
    Cheers,
    It pulls data from linked tables and then updates data using passthrough queries.

    Quote Originally Posted by ArviLaanemets View Post
    Are your users trying all to use the same Access front-end, or do they have their own copies of it?
    They are all going to be trying to use the same front-end. The DB is not split. I want to avoid having to make a version for each person incase I need to update it in the future.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    They are all going to be trying to use the same front-end. The DB is not split. I want to avoid having to make a version for each person incase I need to update it in the future.
    Big, BIg, BIG mistake.

    However if you are using SQL server, it must be split surely? but they still need their own copy of the FE.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    Vita's Avatar
    Vita is offline Competent Performer
    Windows 10 Access 2002
    Join Date
    May 2022
    Location
    Massachusetts, USA
    Posts
    296
    Quote Originally Posted by Welshgasman View Post
    Big, BIg, BIG mistake.

    However if you are using SQL server, it must be split surely? but they still need their own copy of the FE.
    the SQL server is on a separate computer so I suppose this could be considered a frontend?
    Its a simple dropdown and textbox that searches for a record using 3 primary keys and updates some fields and creates some records using a passthrough.
    I was hoping I could just have this one frontend and have everyone use a shortcut to it so I can avoid having to update several different frontends incase they request additional features.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    No, definitely not the way to do it.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    Vita's Avatar
    Vita is offline Competent Performer
    Windows 10 Access 2002
    Join Date
    May 2022
    Location
    Massachusetts, USA
    Posts
    296
    Quote Originally Posted by Welshgasman View Post
    No, definitely not the way to do it.
    How should I have done it?? Why isn't this the way? Is there a way to do it as I am describing?

  9. #9
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    Quote Originally Posted by Vita View Post
    How should I have done it?? Why isn't this the way? Is there a way to do it as I am describing?
    Having all the users share the same front end is a recipe for disaster.
    I supposed you could use group policy or whatever to push the new front end out to everyone, or put it in a shared folder where users can download it

  10. #10
    Vita's Avatar
    Vita is offline Competent Performer
    Windows 10 Access 2002
    Join Date
    May 2022
    Location
    Massachusetts, USA
    Posts
    296
    Quote Originally Posted by madpiet View Post
    Having all the users share the same front end is a recipe for disaster.
    I supposed you could use group policy or whatever to push the new front end out to everyone, or put it in a shared folder where users can download it
    The alternative I am trying to avoid is just make a copy of the front end for everyone and put them on the network drive and give everyone shortcuts to their respective frontend (which is what we currently do with a separate database).

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    The easiest for you atm, is to give everyone a shortcut which copies the latest version to each users computer each time and opens that db.
    A more sophisticated method, is for the db to check its version and update automatically, but little steps first.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #12
    Vita's Avatar
    Vita is offline Competent Performer
    Windows 10 Access 2002
    Join Date
    May 2022
    Location
    Massachusetts, USA
    Posts
    296
    Quote Originally Posted by Welshgasman View Post
    The easiest for you atm, is to give everyone a shortcut which copies the latest version to each users computer each time and opens that db.
    A more sophisticated method, is for the db to check its version and update automatically, but little steps first.
    How should I go about doing this? I like this! I wanna jump straight to the sophisticated version tbh.

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Well I used Bob Larsen's Auto Update code
    You will need to google for that


    But he even mentions another coder
    http://www.autofeupdater.com/

    Vlad (@Gicu) also has one I seem to recall
    http://forestbyte.com/ms-access-util...G3a5bsYECzLvNI
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  14. #14
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    That is another nice method.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 02-01-2021, 08:52 AM
  2. Replies: 4
    Last Post: 04-02-2018, 05:06 PM
  3. Replies: 10
    Last Post: 05-02-2016, 12:19 PM
  4. Replies: 3
    Last Post: 08-26-2015, 09:46 AM
  5. Replies: 1
    Last Post: 08-25-2011, 11:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums