Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Crashing on db.exec_ when the file is run for the second time
QtWS25 Last Chance

Crashing on db.exec_ when the file is run for the second time

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 564 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    knee_boarder
    wrote on last edited by
    #1

    I have two issues - first off (and more importantly) the second time the code is run from the QGIS Python console it fails with "The thread tried to read from or write to a virtual address for which it does not have the appropriate access". It's crashing on db.exec_

    The db is SQL Server 2008 r2 and we're running the 32bit version of QGIS.

    The second issue is that if I close and remove the database the table displayed using projectView.show() is empty yet if I comment those lines out, the data displays correctly.

    @from PyQt4.QtSql import *
    from PyQt4.QtGui import *
    from qgis.gui import *

    db = QSqlDatabase.addDatabase('QODBC')
    if db.isValid():
    db.setDatabaseName('DRIVER={SQL Server};SERVER=%s;DATABASE=%s;UID=%s;PWD=%s;'
    % ('ServerName',
    'Database',
    'username',
    'password'))

    #print "db.isValid"
    
    if db.open():
        #print "success"
        query = db.exec_("""SELECT TOP 100 postal_address as address, EASTING as x, NORTHING as y FROM dbo.POSTAL_ADDRESS WHERE postal_address LIKE('%EX3 %')""")
    
        projectModel = QSqlQueryModel()
        projectModel.setQuery(query)
        projectView = QTableView()
        projectView.setModel(projectModel)
    
        projectView.show()    
    
        QMessageBox.warning(None, "Info", "hello")
    
        query = db.exec_("""SELECT TOP 100 postal_address as address, EASTING as x, NORTHING as y FROM dbo.POSTAL_ADDRESS WHERE postal_address LIKE('%EX2 %')""")
    
        projectModel = QSqlQueryModel()
        projectModel.setQuery(query)
        projectView = QTableView()
        projectView.setModel(projectModel)
    
        projectView.show()    
    
        #db.close()
        #db.removeDatabase('QODBC')       
    
    else:
        QMessageBox.warning(None, "Info", "Error")
    

    else:
    QMessageBox.warning(None, "Info", "Error")@

    The error is

    Dump Summary ------------
    Dump File: qgis-20141218-083144-1364-7108-exported.dmp : C:\Users\usr\AppData\Local\Temp\qgis-20141218-083144-1364-7108-exported.dmp
    Last Write Time: 18/12/2014 08:31:44
    Process Name: qgis-bin.exe : C:\Program Files\QGIS Brighton\bin\qgis-bin.exe
    Process Architecture: x64
    Exception Code: 0xC0000005
    Exception Information: The thread tried to read from or write to a virtual address for which it does not have the appropriate access.
    Heap Information: Not Present –

    When the file is run in the QGIS python console the first time, both db.exec_ calls work correctly. When the file is run for the second time, that's when the crash occurs. Could it be an x32 / x64 error? The code I was trying to change originally postgissearch worked fine when connecting to a postgis database but now I'm trying to connect to a sql server db I get the error the second time it runs and the table doesn't display data if I close and remove the database.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved