I got following code. The problem is I could read data use panda.read_sql, but I could not use the DataFrame.to_sql() function.
%matplotlib inline
import pandas as pd
import pyodbc
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt
pd.set_option('display.max_rows', 50)
pd.set_option('display.max_columns', 15)
pd.set_option('precision', 4)
conn = pyodbc.connect(r"Driver={SQL Server};Server=dev;Database=test1")
data = pd.read_sql_query(
"""
SELECT *
FROM sys.tables
"""
, con = conn)
print data
data.to_sql('test', con = conn)
the error is the following:
Execution failed on sql 'SELECT name FROM sqlite_master WHERE type='table' AND name=?;': ('42S02', "[42S02] [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'sqlite_master'. (208) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)")
Is there a way to get around?
testtable exist in database indboschema? If not use the if_exists argument to replace/append. The default is fail.to_sqldoes not support MS SQL Server connection directly, you need to use sqlalchemy to connect as shown in the answer of @Parfait