Python Database connection Close

前端 未结 5 993
一个人的身影
一个人的身影 2021-01-30 03:57

Using the code below leaves me with an open connection, how do I close?

import pyodbc
conn = pyodbc.connect(\'DRIVER=MySQL ODBC 5.1 driver;SERVER=localhost;D         


        
5条回答
  •  不要未来只要你来
    2021-01-30 04:24

    According to pyodbc documentation, connections to the SQL server are not closed by default. Some database drivers do not close connections when close() is called in order to save round-trips to the server.

    To close your connection when you call close() you should set pooling to False:

    import pyodbc
    
    pyodbc.pooling = False
    

提交回复
热议问题