Limiting multiple connections to SQL Server database through pyodbc?Add a column with a default value to an existing table in SQL ServerHow to return only the Date from a SQL Server DateTime datatypeHow to check if a column exists in a SQL Server table?How to concatenate text from multiple rows into a single text string in SQL server?LEFT JOIN vs. LEFT OUTER JOIN in SQL ServerInserting multiple rows in a single SQL query?How do I UPDATE from a SELECT in SQL Server?Find all tables containing column with specified name - MS SQL ServerHow to Delete using INNER JOIN with SQL Server?Python - Pyodbc for SQL Anywhere 16?
Convert a string like 4h53m12s to a total number of seconds in JavaScript
kids pooling money for Lego League and taxes
What is the purpose of the fuel shutoff valve?
Is it legal for private citizens to "impound" e-scooters?
Hold[Expression] (or similar) in InputField that truly holds the input unmodified
A planet illuminated by a black hole?
How do campaign rallies gain candidates votes?
What are the exact meanings of roll, pitch and yaw?
401(k) investment after being fired. Do I own it?
Spoken encryption
Can GPL and BSD licensed applications be used for government work?
Explanation for a joke about a three-legged dog that walks into a bar
What was the rationale behind 36 bit computer architectures?
Do Rabbis get punished in Heaven for wrong interpretations or claims?
How can I make sure my players' decisions have consequences?
Inadvertently nuked my disk permission structure - why?
This message is flooding my syslog, how to find where it comes from?
Why did Saturn V not head straight to the moon?
Closet Wall, is it Load Bearing?
Character is called by their first initial. How do I write it?
Grid/table with lots of buttons
Sextortion with actual password not found in leaks
Is Grandpa Irrational? Another Grandpa Mystery
Spacing setting of math mode
Limiting multiple connections to SQL Server database through pyodbc?
Add a column with a default value to an existing table in SQL ServerHow to return only the Date from a SQL Server DateTime datatypeHow to check if a column exists in a SQL Server table?How to concatenate text from multiple rows into a single text string in SQL server?LEFT JOIN vs. LEFT OUTER JOIN in SQL ServerInserting multiple rows in a single SQL query?How do I UPDATE from a SELECT in SQL Server?Find all tables containing column with specified name - MS SQL ServerHow to Delete using INNER JOIN with SQL Server?Python - Pyodbc for SQL Anywhere 16?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I use pyodbc to connect to a server and pull data into dataframes using the pandas.read_sql method. I then populate a report with the data from these dataframes. I want to ensure that I'm not creating multiple connections to the db without closing them unless absolutely needed.
Currently I get the results I want but my code connects to the db too many times increasing overhead, blocking processes, etc.
def connect_db(server=server_name):
config =
'DRIVER': 'ODBC Driver 13 for SQL Server',
'TRUSTED_CONNECTION': 'Yes',
'SERVER': server
conn = pyodbc.connect(**config)
return conn
def pull_sales(conn=connect_db()):
with open(sales_query) as f:
sales_sql = sales_query
data = pd.read_sql(sales_sql, conn)
return data
def pull_employees(conn=connect_db()):
with open(employee_query) as f:
employee_sql = employee_query
data = pd.read_sql(employee_sql, conn)
return data
How can I still pull the employees and sales data as I am above, while ensuring I'm not creating multiple connections without closing them? Thanks!
python sql sql-server pyodbc database-administration
add a comment |
I use pyodbc to connect to a server and pull data into dataframes using the pandas.read_sql method. I then populate a report with the data from these dataframes. I want to ensure that I'm not creating multiple connections to the db without closing them unless absolutely needed.
Currently I get the results I want but my code connects to the db too many times increasing overhead, blocking processes, etc.
def connect_db(server=server_name):
config =
'DRIVER': 'ODBC Driver 13 for SQL Server',
'TRUSTED_CONNECTION': 'Yes',
'SERVER': server
conn = pyodbc.connect(**config)
return conn
def pull_sales(conn=connect_db()):
with open(sales_query) as f:
sales_sql = sales_query
data = pd.read_sql(sales_sql, conn)
return data
def pull_employees(conn=connect_db()):
with open(employee_query) as f:
employee_sql = employee_query
data = pd.read_sql(employee_sql, conn)
return data
How can I still pull the employees and sales data as I am above, while ensuring I'm not creating multiple connections without closing them? Thanks!
python sql sql-server pyodbc database-administration
add a comment |
I use pyodbc to connect to a server and pull data into dataframes using the pandas.read_sql method. I then populate a report with the data from these dataframes. I want to ensure that I'm not creating multiple connections to the db without closing them unless absolutely needed.
Currently I get the results I want but my code connects to the db too many times increasing overhead, blocking processes, etc.
def connect_db(server=server_name):
config =
'DRIVER': 'ODBC Driver 13 for SQL Server',
'TRUSTED_CONNECTION': 'Yes',
'SERVER': server
conn = pyodbc.connect(**config)
return conn
def pull_sales(conn=connect_db()):
with open(sales_query) as f:
sales_sql = sales_query
data = pd.read_sql(sales_sql, conn)
return data
def pull_employees(conn=connect_db()):
with open(employee_query) as f:
employee_sql = employee_query
data = pd.read_sql(employee_sql, conn)
return data
How can I still pull the employees and sales data as I am above, while ensuring I'm not creating multiple connections without closing them? Thanks!
python sql sql-server pyodbc database-administration
I use pyodbc to connect to a server and pull data into dataframes using the pandas.read_sql method. I then populate a report with the data from these dataframes. I want to ensure that I'm not creating multiple connections to the db without closing them unless absolutely needed.
Currently I get the results I want but my code connects to the db too many times increasing overhead, blocking processes, etc.
def connect_db(server=server_name):
config =
'DRIVER': 'ODBC Driver 13 for SQL Server',
'TRUSTED_CONNECTION': 'Yes',
'SERVER': server
conn = pyodbc.connect(**config)
return conn
def pull_sales(conn=connect_db()):
with open(sales_query) as f:
sales_sql = sales_query
data = pd.read_sql(sales_sql, conn)
return data
def pull_employees(conn=connect_db()):
with open(employee_query) as f:
employee_sql = employee_query
data = pd.read_sql(employee_sql, conn)
return data
How can I still pull the employees and sales data as I am above, while ensuring I'm not creating multiple connections without closing them? Thanks!
python sql sql-server pyodbc database-administration
python sql sql-server pyodbc database-administration
asked Mar 26 at 16:08
Arjun ArunArjun Arun
821 silver badge8 bronze badges
821 silver badge8 bronze badges
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361588%2flimiting-multiple-connections-to-sql-server-database-through-pyodbc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361588%2flimiting-multiple-connections-to-sql-server-database-through-pyodbc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown