Created
May 29, 2020 05:09
-
-
Save Brand2/98d81241131a94592aef4287c0dbf943 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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