Python Forum

Full Version: SQL Server Question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When closing out of a instance of SQL Server, do I need to destroy the instance or is closing enough?

#Close the connection
rst.Close()
cn.Close()

rst = None
cn = None
Closing is enough, garbage collector will do the rest. However it's better to use with context manager and it will close connection for you e.g. http://pymssql.org/en/stable/pymssql_exa...t-managers. What package do you use to interact with the DB?
Dispatch from pypiwin32

from win32com.client import Dispatch #pip install pypiwin32
pypiwin32? That's strange choice. Not sure how actively developed it is. Also no docs.

It's not Mark Hammond's popular pywin32 package. More like old fork.
If I were you I would consider some other packages -pymssql, pyodbc, etc.
Also look at sqlalchemy - https://docs.sqlalchemy.org/en/latest/di...mssql.html
if you select to use adodbapi, prerequisite is Hammond's pywin32 - http://adodbapi.sourceforge.net/