mgear mgear - 1 year ago 186
Python Question

web2py database always locked when trying to update from code

Trying to simply update existing row in database (running on web2py),
but always getting database locked error..

Error message:

<class 'sqlite3.OperationalError'> database is locked

My setup

  • in models/ I create database and it works when using database administration (can insert, update using the web interface)

    db.define_table('mytest', Field('name', 'string'))

  • I have added 1 row to mytest, using the web interface (so its not empty)

  • in controllers/ i have simple code to get first item and try to update the value, there it fails (I open the page is browser and it gives the internal error, with link to error log)

    def index():
    # connect
    db = DAL('sqlite://storage.sqlite',pool_size=10,auto_import=True)

    # get first record
    record = db(db.mytest).select().first()

    # try to update it.. database locked error here

    # just in case needed?

    return "test"


  • WinPython2.7

  • Running (2.14.6) manually using Spyder ide

  • windows8

What i've tried so far

  • Different DAL settings, poolsize, without autoimport..

  • Close all web2py admin tools/tabs

  • Create new database

  • Restart web2py

  • Restart pc

Error log:

Current workaround:
- Create New Application, exact same code seems to work there

Answer Source

Check Whether there is no other connection (to sqlite db) open on your machine, if web2py shell is open, close it.

Check DAL is defined only once or not. Define DAL only in models/, no need to define it again in controller.

Every variable defined in models is visible in controllers.

You must have defined DAL in models/ and you are defining once again in controller, so you have two connection open for SQLite db. Thats why you are getting error 'database is locked'.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download