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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.