Answers for "python how to connect to sql server"

SQL
0

python how to connect to sql server

import pandas as pd
import pyodbc 

conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=RON\SQLEXPRESS;'
                      'Database=test_database;'
                      'Trusted_Connection=yes;')

df = pd.read_sql_query('SELECT * FROM products', conn)

print(df)
print(type(df))
Posted by: Guest on April-02-2022
0

connect to sql database python

import sqlite3

try:
    sqliteConnection = sqlite3.connect('test.db')
    cursor = sqliteConnection.cursor()
    print("SQLITE Connection Established!")
    cursor.close()

except sqlite3.Error as error:
    print("Error while connecting to sqlite", error)
finally:
    if (sqliteConnection):
        sqliteConnection.close()
        print("Connection closed")
Posted by: Guest on April-22-2022

Code answers related to "python how to connect to sql server"

Code answers related to "SQL"

Browse Popular Code Answers by Language