2

I am currently learning how to set up a local Microsoft SQL database with the goal of making it online in the future.

My question is about the max number of connections which are allowed at any one time.

#import required packages
import pyodbc

#define connection
conn = pyodbc.connect('connection string')

#create cursor
cursor = conn.cursor()
cursor2 = conn.cursor()

#check how many max connections available
how_many = conn.getinfo(pyodbc.SQL_MAX_CONCURRENT_ACTIVITIES)
print(how_many)

The answer I get with this is 1. Is this due to the fact that the database is local or will I get this same answer once I make the database online?

I don't want to keep working on this if I have chosen the wrong type of database even though google is telling me that MS SQL can handle ~32k connections at once.

My attempt to see if the max is indeed 2 is the following, everything works without error:

#use cursor 1 to query the database
this = cursor.execute('select * from tablename')

#get all data from the table in the database
rows = this.fetchall()

#loop over rows and print each row to the terminal
for row in rows:
    print(row)

this2 = cursor2.execute('select * from tablename')
rows2 = this2.fetchall()
for row in rows2:
    print(row)

#commit the connection, close the cursors, close the connection
conn.commit()
cursor.close()
cursor2.close()
conn.close() 

Is this the correct way to test for this? Does this count as 2 concurrent connections?

5
  • 2
    If you check SQL Server's docs you'll see that ODBC setting refers to how many statements can be active at the same time in one connection and Some drivers limit the number of active statements they support; the SQL_MAX_CONCURRENT_ACTIVITIES option in SQLGetInfo specifies how many active statements a driver supports on a single connection. Which ODBC driver are you using? pyodbc is the Python library that talks to the ODBC driver, not the driver itself Commented Aug 26, 2020 at 15:51
  • Ah, I see. The driver I'm user is FreeTDS which, from a quick google search, allows more than one connection but I just have to configure it differently. Thank you. Commented Aug 28, 2020 at 11:17
  • 1
    Why don't you use Microsoft's ODBC provider? FreeTDS has some .... critical problems, to put it mildly. It doesn't even support parameters because the author thought they aren't commonly used. Which would be a surprise to hundreds of thousands of programmers going back to VB6. The lack of parameterized queries should make FreeTDS unsuitable for any kind of production environment Commented Aug 28, 2020 at 11:19
  • 1
    SQL Server docs contain a step-by-step guide to install the proper drivers and connect to SQL Server with ODBC Commented Aug 28, 2020 at 11:23
  • There is no real reason as to why I'm using FreeTDS, it's just what was in the tutorial I followed for connecting python with a SQL database. I will definitely check out other alternatives. Thanks for that guide too. Commented Aug 28, 2020 at 12:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.