OK guys, it seems so I found the source of the problem. Probably the problem was with the ODBC settings. The ODBC fetch array size was 5000 and the network connection to the DB server is so poor that the ODBC driver could not handle this size of data package transfer.
So after we decreased the fetch array size to 50 the script works agains. The speed of the loading data process is not so good, but it works.