Upload csv file to sqlserver with python
First of all, when in doubt, profile.

Now a not-so-wild guess. Most of the time is wasted in

    qcnt="select count(1) from "+tb
    resq=c.execute(qcnt)
    rq=c.fetchone()
    rq=str(rq[0])


In fact, the rq is incremented by each successful insert. Better fetch it once, and increment it locally:

    qcnt="select count(1) from "+tb
    resq=c.execute(qcnt)
    rq=c.fetchone()

    for row in csvfile:
        ....
        insert = ....
        c.execute(insert)
        rq += 1
        ....


Another guess is that committing each insert separately also does not help with performance. Do it once, after the loop. In any case, you must check the success of each commit.



Notice that if there is more than one client updating the table simultaneously, there is a data race (clients fetching the same rq), both with the original design, and with my suggestion. Moving rq into a column of its own may help; I don't know your DB design and requirements.

Consider a single insert values, wrapped into a transaction, instead of multiple independent inserts.



Testing for cnt &gt; 0 is also wasteful. Read and discard the first line; then loop for the remaining rows.



Figuring out whether a field represents a date seems strange. You shall know that in advance.