<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Christian Riesen &#187; MS SQL</title>
	<atom:link href="http://christianriesen.com/tag/ms-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://christianriesen.com</link>
	<description>Life and work in the information and communication age</description>
	<lastBuildDate>Fri, 24 Feb 2012 09:55:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MS SQL Blob truncated</title>
		<link>http://christianriesen.com/2010/07/ms-sql-blob-truncated/</link>
		<comments>http://christianriesen.com/2010/07/ms-sql-blob-truncated/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 10:39:53 +0000</pubDate>
		<dc:creator>Christian Riesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Blob]]></category>
		<category><![CDATA[FreeTDS]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[MS SQL]]></category>

		<guid isPermaLink="false">http://christianriesen.com/?p=212</guid>
		<description><![CDATA[There are times when I wish I had a third hand, just so I could to a triple face palm. This is one of those times. I&#8217;m accessing a blob in a MS SQL database that is pretty much nothing more than a JPG dumped straight into the field. I read them and echo them [...]]]></description>
			<content:encoded><![CDATA[<p>There are times when I wish I had a third hand, just so I could to a triple face palm. This is one of those times.</p>
<p>I&#8217;m accessing a blob in a MS SQL database that is pretty much nothing more than a JPG dumped straight into the field. I read them and echo them with a jpg header in PHP. All is well. The script runs and parses all the images, doing some caching magic with them. The result is that about a third of the images are broken, seemingly random. Mostly they just &#8220;stop&#8221; at a random spot over the whole set, but in one image it always stops at the same spot.</p>
<p>I suspected data corruption on input and a refresh on what inserts them in the first place worked, sometimes at least.</p>
<p>Digging down, I saw that the result I get back for the broken images is always 64512 bytes, exactly. That&#8217;s 2 to the power of 16. Can&#8217;t be a coincidence. Turns out, it isn&#8217;t.</p>
<p>I&#8217;m using freetds to access the database and there is an entry in freetds.conf that reads something like this:<br />
text size = 64512</p>
<p>Upping that number (and restarting the webserver, apache or IIS) did the trick. The images stored in the database were all around that point, so it looked like a random bug, but thankfully it wasn&#8217;t random.</p>
<p>If you don&#8217;t use freetds but the mssql extension instead, then this line would be of interest:<br />
mssql.textsize = 4096</p>
<p>Yes the default is only 4 kilobytes.</p>
<p>Maybe the desk will work as a third hand for the triple face palm.</p>
 <p><a href="http://christianriesen.com/?flattrss_redirect&amp;id=212&amp;md5=542976ad1acaf4ac41050fcc69085fa7" title="Flattr" target="_blank"><img src="http://christianriesen.com/wp-content/plugins/flattrss/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://christianriesen.com/2010/07/ms-sql-blob-truncated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="https://flattr.com/submit/auto?user_id=756&amp;url=http%3A%2F%2Fchristianriesen.com%2F2010%2F07%2Fms-sql-blob-truncated%2F&amp;language=en_GB&amp;category=text&amp;title=MS+SQL+Blob+truncated&amp;description=There+are+times+when+I+wish+I+had+a+third+hand%2C+just+so+I+could+to+a+triple+face+palm.+This+is+one+of+those+times.%0D%0A%0D%0AI%27m+accessing+a+blob+in+a+MS+SQL+database+that+is+pretty+much+nothing+more+than+a+JPG+dumped+straight+into+the+field.+I+read+them+and+echo+them+with+a+jpg+header+in+PHP.+All+is+well.+The+script+runs+and+parses+all+the+images%2C+doing+some+caching+magic+with+them.+The+result+is+that+about+a+third+of+the+images+are+broken%2C+seemingly+random.+Mostly+they+just+%22stop%22+at+a+random+spot+over+the+whole+set%2C+but+in+one+image+it+always+stops+at+the+same+spot.%0D%0A%0D%0AI+suspected+data+corruption+on+input+and+a+refresh+on+what+inserts+them+in+the+first+place+worked%2C+sometimes+at+least.%0D%0A%0D%0ADigging+down%2C+I+saw+that+the+result+I+get+back+for+the+broken+images+is+always+64512+bytes%2C+exactly.+That%27s+2+to+the+power+of+16.+Can%27t+be+a+coincidence.+Turns+out%2C+it+isn%27t.%0D%0A%0D%0AI%27m+using+freetds+to+access+the+database+and+there+is+an+entry+in+freetds.conf+that+reads+something+like+this%3A%0D%0Atext+size+%3D+64512%0D%0A%0D%0AUpping+that+number+%28and+restarting+the+webserver%2C+apache+or+IIS%29+did+the+trick.+The+images+stored+in+the+database+were+all+around+that+point%2C+so+it+looked+like+a+random+bug%2C+but+thankfully+it+wasn%27t+random.%0D%0A%0D%0AIf+you+don%27t+use+freetds+but+the+mssql+extension+instead%2C+then+this+line+would+be+of+interest%3A%0D%0Amssql.textsize+%3D+4096%0D%0A%0D%0AYes+the+default+is+only+4+kilobytes.%0D%0A%0D%0AMaybe+the+desk+will+work+as+a+third+hand+for+the+triple+face+palm.&amp;tags=Blob%2CFreeTDS%2CImages%2CMS+SQL%2Cblog" type="text/html" />
	</item>
	</channel>
</rss>

