title: ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Incorrect syntax near '@P1'. (102)
body: <p>Here is my code. I am getting error at 'BULK INSERT' statement. Please tell why the bulk insert is not working:</p>
  
  <pre><code>local_path="C:\\Users\\sankalp.patil\\assignment\\upload" 
  
  block_blob_service = BlockBlobService(account_name='samplsa', account_key='+M5icqu9BNzqTMfYMsYhFEROBjdgFHMIyYytsbBRqATVllUP0XyHcsgbxGmEC4zu0QtpW7rAn2Vf4PsBMVa5eg==')
  container_name = 'targetcontainer'
  block_blob_service.create_container(container_name)
  
  for files in os.listdir(local_path): block_blob_service.create_blob_from_path(container_name,files,os.path.join(local_path,files))
  
  server = 'sample-server1.database.windows.net'    
  database = 'targetdb'    
  username = 'sankalp'    
  password = 'mypassword'    
  driver= '{ODBC Driver 13 for SQL Server}'
  def sqlconnect(server,database,username,password):
      try:
          return pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password)
      except:
      print ("connection failed check authorization parameters")  
  conn = sqlconnect(server,database,username,password)
  cursor = conn.cursor()
  
  
  for files in os.listdir(local_path):
      path=os.path.join(local_path,files)
      filename=(os.path.splitext(files)[0])
      tablename = 'dbo.'+filename
      print(files)
      print(path)
      print(tablename)
      sql = "BULK INSERT ? FROM ? WITH (DATA_SOURCE = 'j',FIELDTERMINATOR=',',ROWTERMINATOR='\n')", tablename , files
  cursor.execute(*sql)
  
  conn.commit()
  cursor.close()
  print("Done")
  conn.close()
  
  
  
  
  I have created a data source in azure sql db as follows :
  
  create external data source j
      with(
          type = BLOB_STORAGE,
          location = 'https://samplsa.blob.core.windows.net/targetcontainer'
          )
  </code></pre>
  
  <p>So I am copying files from my system to azure blob storage.And then trying to copy files from blob to azure sql database.But I am getting the error as </p>
  
  <p>Error: </p>
  
  <blockquote>
    <p>[42000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]<br>
    Incorrect syntax near '@P1'<br>
    (102) (SQLExecDirectW); [42000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Statement(s) could not be prepared. (8180)</p>
  </blockquote>