Hướng dẫn python library sql server
Chuyển đến nội dung chính Trình duyệt này không còn được hỗ trợ nữa. Show
Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật. Step 3: Proof of concept connecting to SQL using pyodbc
Trong bài viết nàyThis example is a proof of concept. The sample code is simplified for clarity, and doesn't necessarily represent best practices recommended by Microsoft. To get started, run the following sample script. Create a file called test.py, and add each code snippet as you go.
Connect
Run queryThe cursor.execute function can be used to retrieve a result set from a query against SQL Database. This function accepts a query and returns a result set, which can be iterated over with the use of cursor.fetchone().
Insert a rowIn this example, you see how to run an INSERT statement safely, and pass parameters. The parameters protect your application from SQL injection.
Azure Active Directory and the connection stringpyODBC uses the Microsoft ODBC driver for SQL Server. If your version of the ODBC driver is 17.1 or later, you can use the Azure Active Directory interactive mode of the ODBC driver through pyODBC. This interactive option works if Python and pyODBC permit the ODBC driver to display the dialog. The option is only available on Windows operating systems. Example connection string for Azure Active Directory interactive authenticationThe following example provides an ODBC connection string that specifies Azure Active Directory interactive authentication:
For more information about the authentication options of the ODBC driver, see Using Azure Active Directory with the ODBC Driver. Next stepsFor more information, see the Python Developer Center. Phản hồiGửi và xem ý kiến phản hồi dành cho Chuyển đến nội dung chính Trình duyệt này không còn được hỗ trợ nữa. Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật. Tải xuống Microsoft Edge Xem thêm thông tin về Internet Explorer và Microsoft Edge
Đọc bằng tiếng Anh Đọc bằng tiếng Anh Phản hồi Chỉnh sửa Python SQL driver
Trong bài viết nàyInstall SQL driver for Python You can connect to a SQL Database using Python on Windows, Linux, or macOS. Getting startedThere are several python SQL drivers available. However, Microsoft places its testing efforts and its confidence in pyodbc driver. Choose one of the following drivers, and configure your development environment:
DocumentationFor documentation, see Python documentation at Python.org. Community
Next stepsExplore samples that use Python to connect to a SQL database in the following articles:
Phản hồiGửi và xem ý kiến phản hồi dành cho Sản phẩm này Trang này Xem tất cả ý kiến phản hồi về trang Trong bài viết này |