title: Python execute sql query using sqlcmd
body: <p>Hi I want to execute query using sqlcmd so I am calling it using subprocess.call() . This process sometimes its working but in loop it does not work. It only the execute the last argument. Please help below is the sample code I am trying-</p>
  
  <pre><code>import subprocess
  host = 'hostname'
  db = 'SQLTest'
  sqlcmd = "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE"
  query = "INSERT INTO [dbo].[Test](type,ident,lat,long,y_proj,x_proj,new_seg,display,color,altitude,depth,temp,time,model,filename,ltime) VALUES ('TRACK','ACTIVE LOG','40.79015493','-77.85914183','4627311.94501541','1779470.5827101','False','False','255','351.979858398438','0','0','2008/06/11-14:33:33','eTrex Venture','','2008/06/11 09:33:33')"
  for x in range (0,5):
      subprocess.call([sqlcmd,'-S' ,host, '-d', db, '-Q', query])
  </code></pre>
  
  <p>Or is there any other method. I even tried pymysql module. But it shows authentication error.</p>