I have a bash script that reads from a remote MSSQL server 2008 using FreeTDS.
Using tsql
, I am able to make individual queries and all of them run perfectly separately. However, when I run the bash script that contains multiple queries, I get the following error, after some successful queries:
Error 20003 (severity 6):
Adaptive Server connection timed out
OS error 115, "Operation now in progress"
Error 20002 (severity 9):
Adaptive Server connection failed
There was a problem connecting to the server
Here is my freetds.conf
:
#...
[mssql]
host = <my_ip>
port = 1433
tds version = 7.3
Here is what my bash script looks like:
# ...
TDSVER=7.3 tsql -S mssql -U $USER -P $PASSWORD < $QUERY1_SQL > $OUT1.CSV
TDSVER=7.3 tsql -S mssql -U $USER -P $PASSWORD < $QUERY2_SQL > $OUT2.CSV
TDSVER=7.3 tsql -S mssql -U $USER -P $PASSWORD < $QUERY3_SQL > $OUT3.CSV
TDSVER=7.3 tsql -S mssql -U $USER -P $PASSWORD < $QUERY4_SQL > $OUT4.CSV
# ...
I read that the error i'm getting is likely due to wrong TDS version, but I don't think that is the case, since I can run each query individually from prompt and successfully get the results. I also tried using TDSVER=8.0, but without success.
I noticed that if I comment some random queries in the bash file, it works without any errors (not any specific queries, though, if I comment query1 and query2, for example it works, but if I leave query1 and query2 uncommented and comment query3 and query4, it also works). What is the problem here?