title: Insert binary file into MSSQL db (varbinary) with python pymssql
body: <p>I'm trying to insert binary data into an MSSQL database using <em>stored procedures</em> from within an pyramid web application using pymssql.</p>
  
  <p>The MSSQL datatype for the respective column is <code>varbinary(max)</code>.</p>
  
  <p>My question is: <strong>What does the varbinary datatype of the MSSQL database expect me to do with the binary file before inserting it?</strong></p>
  
  <p>Here's what I've been trying:</p>
  
  <pre><code>with open(tmp_file, 'rb') as content_file:
      filecontent = content_file.read()
  </code></pre>
  
  <p>... and then pass the value of <code>filecontent</code> to the stored procedure.</p>
  
  <p><code>tmp_file</code> in this case is a valid path to a <code>.png</code> file.</p>
  
  <p>The MSSQL db answers with the following error:</p>
  
  <pre><code>*** DatabaseError: (257, 'Implicit conversion from data type varchar to varbinary(max) is not 
  allowed. Use the CONVERT function to run this query.DB-Lib error message 257, severity 16:\nGeneral
  SQL Server error: Check messages from the SQL Server\n')
  </code></pre>
  
  <p>I am able to insert the value of the <code>filecontent</code> variable into an SQLite (<code>varbinary</code> column) and a MySQL database (<code>BLOB</code> column) no problem. </p>
  
  <p>Why is it not working with the MSSQL db?</p>