MarkPryceMaherMSFT/testcode

★ 0Forks 0PythonGitHub ↗Compare

README

SQL Server Schema Viewer

A Python desktop application for connecting to SQL Server databases and viewing their schema.

Features

  • Multiple Authentication Types:

    • SQL Server Authentication (username/password)
    • Windows Authentication (Trusted Connection)
    • Azure Active Directory Password
    • Azure Active Directory Integrated
    • Azure Active Directory Interactive (MFA/2-Factor)
    • Azure Active Directory Service Principal
  • Schema Browsing:

    • View all databases on the server
    • Browse tables, views, stored procedures, and functions
    • View column details with data types, nullability, and key information
    • View index information for tables
    • View parameters for stored procedures and functions

Requirements

  • Python 3.8 or later
  • SQL Server ODBC Driver (ODBC Driver 17 or 18 for SQL Server recommended)
  • For Azure AD authentication: Azure AD-enabled SQL Server or Azure SQL Database

Installation

  1. Clone or download this repository:

    cd testcode
  2. Install the required Python packages:

    pip install -r requirements.txt
  3. Ensure you have the SQL Server ODBC driver installed:

Usage

  1. Run the application:

    python main.py
  2. Connect to a SQL Server:

    • Go to File > Connect... or use the menu
    • Enter your server name (e.g., localhost, myserver.database.windows.net)
    • Select the authentication type
    • Enter credentials as required
    • Click Connect
  3. Browse the schema:

    • Select a database from the dropdown
    • Expand the tree to view tables, views, procedures, and functions
    • Click on an object to view its details in the right panel

Authentication Types

SQL Server Authentication

Standard SQL Server login with username and password.

Windows Authentication

Uses your Windows credentials for trusted connections. No username/password required.

Azure AD Password

Azure Active Directory authentication with username and password. Use for Azure SQL Database with AAD integration.

Azure AD Integrated

Uses your current Windows Azure AD credentials. Requires domain-joined machine with Azure AD.

Azure AD Interactive (MFA)

Supports Multi-Factor Authentication. A browser window will open for interactive login. Best for users with MFA enabled.

Azure AD Service Principal

Authentication using an Azure AD application. Requires:

  • Client ID (Application ID)
  • Client Secret
  • Tenant ID (optional for some scenarios)

Project Structure

testcode/
├── main.py           # Application entry point
├── connection.py     # Database connection handling
├── schema_viewer.py  # Schema retrieval and processing
├── gui.py            # Tkinter GUI implementation
├── requirements.txt  # Python dependencies
└── README.md         # This file

Troubleshooting

Driver Not Found

If you see "Driver not found" errors, ensure the ODBC driver is installed:

# Check available drivers (Python)
import pyodbc
print(pyodbc.drivers())

Azure AD Authentication Errors

  • Ensure your SQL Server/Azure SQL supports Azure AD authentication
  • For interactive authentication, allow the browser popup
  • For service principal, verify the client ID and secret are correct

Connection Timeout

Increase the connection timeout in the connection dialog options if connecting to a remote server.

License

This project is provided as-is for educational and development purposes.

Contributors

MarkPryceMaherMSFT

Issues