Questions tagged [varbinary]

varbinary is the SQL Server datatype used to hold variable-length binary data

SQL Server's varbinary datatype is declared with a length specification in the CREATE TABLE statement:

CREATE TABLE tablename (..., colName varbinary(n), ...)

where n is the maximum size of the column in bytes (limited to a maximum of 8000), or the word MAX if more than 8000 bytes might need to be stored. (The absolute maximum size is approximately 2gb as of this writing; consult SQL Server documentation for the exact current maximum.)

For more information, see this entry in the SQL Server online documentation.

411 questions
4
votes
1 answer

How to display MSSQL varbinary(3072) image in PHP?

I have an bitmap image stored in MSSQL, datatype of the column is varbinary(3072). All I want to do with the image in PHP is to display it + store it into a file. How to do that? Couldn't find anything useful on Google nor here on SO. Only thing I…
Erveron
  • 1,908
  • 2
  • 25
  • 48
4
votes
1 answer

How do I prepare a statement with VARBINARY in PHP PDO for MySQL?

This is the code that I'm using to try comparing to a VARBINARY using PHP PDO: $st = $pdo->prepare('SELECT * FROM `xf_ip` WHERE user_id = ? AND ip = ?;'); $st ->execute(array($new_row[':forums_id'], $hexip)); I tried prefacing it with 0x ('0x' .…
PatPeter
  • 394
  • 2
  • 17
4
votes
1 answer

PHP sqlsrv insert/read blob (varbinary) field from database example

I will post this sample for anybody who need help with insert file to varbinary(max) field in sqlsrv DB. Also if you need to read from varbinary field, you can see how I made that. This code is working but all your comments and suggestions are…
user7414051
  • 41
  • 1
  • 2
4
votes
2 answers

MySQL: Cannot create table with VARBINARY?

I am running this query to set up a VARBINARY (I wish for it to be so, for a real reason) field for my database: CREATE TABLE `test_books` (`id` int UNSIGNED NOT NULL,`book` VARBINARY, `timestamp` int(11) NOT NULL, UNIQUE KEY `id` (`id`)) It hands…
John
  • 3,238
  • 4
  • 22
  • 25
4
votes
1 answer

Loading images from varbinary faster

I'm developing a website using ASP.NET and C# as the code-behind. I have a MSSQL database that contains images saved as varbinary(max). I'm retrieving them and converting the byte array into Base64String in order to show it in my website using CSS…
Omer Aviv
  • 286
  • 3
  • 20
4
votes
1 answer

saving bytearray to VarBinary column in SQL Server inserts only one byte

I have a following problem - I'm trying to save byte[] to database and I just figured out that it works for one byte only. I have number of floats that I convert to byte[] and use that as a parameter: param = new SqlParameter(name, type,…
pzaj
  • 1,062
  • 1
  • 17
  • 37
4
votes
4 answers

Set Linq To Sql Binary field to null

Trying to set a Binary field to null gives me an ArgumentNull exception. I can set the field to be empty like this new Binary(new byte[] {}); but that's not null just an empty column. Is there a workaround using LinqToSql ?
Karsten
  • 8,015
  • 8
  • 48
  • 83
4
votes
2 answers

Insert byte array into SQL Server from C# and how to retrieve it

I'm trying to insert this byte array into a SQL Server database, the column data type is varbinary and this is my code in C# SqlParameter param = new SqlParameter("@buffer", SqlDbType.VarBinary, 8000); param.Value = buffer; string _query = "INSERT…
Ibraheem Al-Saady
  • 854
  • 3
  • 14
  • 30
4
votes
1 answer

Semantics of .WRITE(NULL, NULL, NULL) when updating a VARBINARY(max) column

What are the semantics of the following query UPDATE table SET column .WRITE(NULL, NULL, NULL) if column is of VARBINARY(max) type and its contents are not NULL? A quick test suggests that the query is a no-op: --DROP TABLE [table] CREATE TABLE…
krlmlr
  • 25,056
  • 14
  • 120
  • 217
4
votes
1 answer

duplicate issue when inserint value to varbinary

We face a very weird issue. we have one table in our mssql 2008 R2 db when table column is the follow: userId - int userName - varbinary(256) userType - int and userName column is unique we preform the following query again the table: insert…
MoShe
  • 6,197
  • 17
  • 51
  • 77
4
votes
1 answer

If I Query a SQL Server VarBinary(MAX) Column, Will the Entire File be Loaded In Memory?

My application is using SQL Server 2008 and we need to add functionality for users to optionally be able to save any file of any size to a database table. I have set up the table similar to this format: FileStorageID - int (indentity PK) (This is…
Brandon Nicoll
  • 434
  • 2
  • 10
4
votes
1 answer

Using variable to specify 'size' when declaring a VARBINARY

In SQL Server (2008 R2), instead of doing this: DECLARE @testVar VARBINARY(64); I would like to do this: DECLARE @varSize INT; SET @varSize = 64; DECLARE @testVar VARBINARY(@varSize); But I get this error: Incorrect syntax near '@varSize'. How…
pcantin
  • 554
  • 8
  • 17
3
votes
2 answers

Using MD5 in SQL Server 2005 to do a checksum file on a varbinary

Im trying to do a MD5 check for a file uploaded to a varbinary field in MSSQL 2005. I uploaded the file and using SELECT DATALENGTH(thefile) FROM table I get the same number of bytes that the file has. But using MD5 calculator (from bullzip) i get…
Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
3
votes
1 answer

Sql 2008 Filestream with NHibernate

I am attempting to use Filestream in sql server 2008 to store user uploaded images. My problem is that NHibernate will not error, but it also will not save the data into the database. No record is created. The Image class below is a custom class…
Josh
  • 16,286
  • 25
  • 113
  • 158
3
votes
3 answers

Can I treat Varbinary and bytea fields equivalently?

I moved a mysql DB to Postgres, but some of the tables had a varbinary(16) field (to store an ip address). Postgres does not support varbinary fields, and after some research, I found that the Postgres equivalent is bytea. So, I went ahead and…
zermy
  • 611
  • 1
  • 11
  • 25