Guangning Yu's Blog
Home
Code
Data
Setup
Industry
MachineLearning
Archive
Setup SQL Server and pyodbc
2019-03-05 10:59:13
# Installation - [Microsoft ODBC Driver 17 for SQL Server](https://docs.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-2017) - need admin permission - [SQL Server Management Studio (SSMS)](https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-2017) - need admin permission - [Microsoft SQL Server 2008 Express](https://www.microsoft.com/en-US/download/details.aspx?id=1695) - need admin permission - [issue: The specified credentials that were provided for the SQL Server service are not valid](https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f4fef001-289d-422e-8f42-0b940e3c9410/the-specified-credentials-that-were-provided-for-the-sql-server-service-are-not-valid?forum=sqlsetupandupgrade) - [pyodbc](https://pypi.org/project/pyodbc/) - pip install pyodbc # Setup SQL Server - [Set "mixed mode authentication"](https://stackoverflow.com/questions/17372606/sqlserver-login-failed-for-user) - [Create a database](https://support.gfi.com/hc/en-us/articles/360012876374-How-to-create-a-new-database-in-Microsoft-SQL-Server) - [Create and Configure a User in MSSQL](https://support.rackspace.com/how-to/creating-and-configuring-a-user-in-mssql/) - uncheck "User must change password at next login" - [Create a table](https://docs.microsoft.com/en-us/sql/relational-databases/tables/create-tables-database-engine?view=sql-server-2017) # Connect pyodbc to SQL Server ``` import pyodbc conn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=test;DATABASE=test;UID=user;PWD=password') cursor = conn.cursor() for row in cursor.tables(): print(row.table_name) ```
Previous:
Load Excel file into SQL Server
Next:
Access another container in Docker