# Sql server and varbinary columns

**URL:** <https://www.ruby-forum.com/t/sql-server-and-varbinary-columns/70296>\
**Category:** Rails\
**Created:** [September 28, 2006, 12:20am UTC](https://www.ruby-forum.com/t/sql-server-and-varbinary-columns/70296 "2006-09-28T00:20:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 28, 2006, 12:20am UTC](https://www.ruby-forum.com/t/sql-server-and-varbinary-columns/70296/1 "2006-09-28T00:20:19Z")

</div>

anyone know how to pass a file to a varbinary column right now I’m  
trying this.

view:  
\<% file\_field ‘stored\_files’, ‘tmp\_file’, :enctype =\>  
‘application/binary’ %\>

controller:  
params[:stored\_files][:file] = params[:stored\_files][:tmp\_file].read  
params[:stored\_files].delete(‘tmp\_file’)  
#then regular controller create stuff new save etc…

This causes active record to try and create the varbinary object using  
a sql INSERT statement:

PredefinedTestParameter Create (0.000000) DBI::DatabaseError: 22005  
(257) [unixODBC][FreeTDS][SQL Server]Implicit conversion from data type  
varchar(max) to varbinary(max) is not allowed. Use the CONVERT function  
to run this query.: INSERT INTO predefined\_test\_parameter  
([numeric\_value], [data\_type], , [object\_value],  
[param\_name], [step\_id], [string\_value], [sort], [test\_run\_id],  
[test\_session\_id]) VALUES(NULL, ‘File’, NULL,  
‘%PDF-1.2%00%âaIO%00%01202 0 obj%00\<\< %00/Linearized 1 %00/O 205 %00/H  
[1462 229] %00/L 35078 %00/E 12235 %00/N 1 %00/T 30919 %00\>\>  
%00endobj%00 xref%00202 32 %000000000016 00000 n%00%010000000991 00000  
n%00%010000001324 00000n%00%010000001691 000’)

this produces an error from sqlserver because you are trying to pass a  
varchar to a varbinary. any idea how this is supposed to work on ruby  
on rails? My application server is on linux, does it need to be on  
windows to get this to work?
