I have a Python script using socket and threads to allow 10 servers to connect to a port. Each server dumps a string of data. Sometimes the data comes in rapidly, and other times it trickles in.
The Python script takes the data blob, does a substring count to get "column" values, then sends it to MSSQL using pymssql. Pretty straight forward.
Here's a snippet of the MSSQL portion of the script:
dbConn = pymssql.connect(server=mssql_server, user=mssql_user, password=mssql_pass, database=mssql_db)
cursor = dbConn.cursor()
date = data[0:6]
time = data[7:11]
duration = data[12:16]
mssql_output_raw = "('%s','%s','%s');" % (date, time, duration)
mssql_output = mssql_output_raw.replace(" ", "") # Remove any whitespace
# Write to MSSQL table
try:
query = "INSERT INTO %s VALUES %s" % (mssql_table, mssql_output)
cursor.execute( query )
dbConn.commit()
except pymssql.OperationalError as e:
logmsg("pymssql.OperationalError exception caught: %s" % str(e).replace("\n", " ") )
except:
pass
Every so often (and maybe when the data is rapidly coming in?) I'll get this exception:
20019,
'DB-Lib error message 20019, severity 7:
Attempt to initiate a new Adaptive Server operation with results pending
The script doesn't crash, and since the script is either a) running in the background; or b) in the foreground but spewing data, I'm not sure if the data ever makes it to MSSQL.
Can anyone share what this error means?
I may have figured this out. In my script I'm using threading. There was 1 SQL connector for all the threads. My guess is that the one SQL connector was getting overwhelmed with all the queries.
I've updated my script so that each thread has its own connector. So far so good.