Skip to content

Instantly share code, notes, and snippets.

@Brand2
Created May 29, 2020 05:09
Show Gist options
  • Save Brand2/98d81241131a94592aef4287c0dbf943 to your computer and use it in GitHub Desktop.
Save Brand2/98d81241131a94592aef4287c0dbf943 to your computer and use it in GitHub Desktop.
def execute_query(params, query):
# Build your engine
engine = create_engine("mssql+pyodbc://some_uri_here/?odbc_connect={}".format(params))
# Sanity check that you even get anything here
with engine.connect() as conn:
result = conn.execute("SELECT 1;")
print(result)
with engine.connect() as conn:
try:
return pd.read_sql_query(query, conn)
except Exception as e:
raise ValueError(e)
execute_query("test", "SELECT 1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment