Is there a way to read the blob partially? - sql-server

I want to read blob partially. For now I can read whole blob with select query e.g.
select image from table where condition
But the blob is too big, so I want to read blob partially, with begin pos and length, (e.g. select partial_read( image, 0, 1024 ) from table where condition)
I just try some new way, but I have no idea. simply I can make blob split. But I can't, because of legacy system, it is forbidden for me.
Can you tell me keyword? Or way?
I am using
SQL Server: 2008 R2
OS: Server 2012

Using SUBSTRING such as AlwaysLearning suggests, is perfect for my task (which is identifying PDF data falsely stored as TIF in blobs). Saves a ton of time.

Related

Saving a large text as zipped on a varchar field on sql server

I'm using VB.net , Entity framework 6 , SQL server 2008R2.
I have a case when on a varchar field I should save a very large text. But the number of characters on this text is not specified so I think that will be very large for that field. ( I know there's a VARCHAR(MAX) but I'm thinking also to have the data size in this field as low as possible ). Also for several reasons I can't use a file to save this text ( keeping only the filename on database ).
So I'm asking if is there any way to keep this large text zipped on database and of course to unzip when reading from database.
But I'm searching for a solution that will work with entity framework.
So if now I'm using :
Myobject.mytext="..... My text...."
How can I transform this in order to put the zipped text ( if is possible )
Thank you !
Sql Server does not support compression 'out of the box' of LOBs (VARCHAR(MAX) where Length>8k). So, the best approach would be to handle compression/decompression on the client, before you put it in the network towards SQL Server
So,
Change your column type to VARBINARY(MAX)
Compress your string (with for example https://stackoverflow.com/a/7343623/1202332)
Use entity framework to save the value in the DB
When reading:
Read column with compressed data (with EF)
Decompress your string

Losing one byte when storing data in SQL Server Image column

We have a legacy Classic ASP app that is using ADODB to store a document in an image column in SQL Server. The problem we are running into is that a single byte is getting lost from most files. We have one instance where a file won't lose a byte so I'm thinking it's potentially size related.
So far we have..
Verified that the correct byte length is being passed to the adodb CreateParameter call.
Used the SQL Server BCP tool to verify that the file is corrupt in SQL Server and not by our extraction. When we extracted the file with BCP it is missing the byte AND we did use the -w parameter.
Does anyone have any advice on what we could try to do next?
UPDATE:
We have done some more research and it appears the byte is disappearing in adodb. We do this..
cmd.Parameters.Append cmd.CreateParameter("SupportDocImage",adLongVarBinary,adParamInput,lSize,sFilePath)
Where lSize would be 123,139 and sFilePath is the binary data (yes.. bad naming)
This actually calls off to a stored procedure and in that stored procedure we will do a DATALENGTH(#Variable) and we instead get 123,138.
Also from what we have seen it is the last byte that gets lost.
Check out this article.
The solution is for Oracle, but it is using ADO all the same.
http://forums.devshed.com/visual-basic-programming-52/inserting-blob-s-via-adodb-stream-using-a-stored-procedure-103030.html
Try adding +1 to the size.
Also, did you check this property off when uploading the image.
cmdSQL.Properties("SPPrmsLOB") = True
Regardless, you still have to write a stored procedure that takes a varbinary(max) or image data type and inserts it into the table.

ColdFusion 8 + MSSQL 2005 and CLOB datatype on resultset

The environment I am working with is CF8 and SQL 2005 and the datatype CLOB is disabled on the CF administrator. My concern is, will there be a performance ramification by enabling the CLOB datatype in the CF Administrator.
The reason I want/need to enable it is, SQL is building the AJAX XML response. When the response is large, the result is either truncated or returned with multiple rows (depending on how the SQL developer created the stored proc). Enabling CLOB allows the entire result to be returned. The other option I have is to have SQL always return the XML result in multiple rows and have CF join the string for each result row.
Anyone with some experience with this idea or have any thoughts?
Thanks!
I really think that returning Clob data is likely to be less expensive then concatenating multiple rows of data into an XML string and then parsing it (ick!). What you are trying to do is what CLOB is designed for. JDBC handles it pretty well. The performance hit is probably negligible. After all - you have to return the same amount of character data either way, whether in multiple rows or a single field. And to have to "break it up" on the SQL side and then "reassemble" it on the CF side seems like reinventing the wheel to be sure.
I would add that questions like this sometimes mystify me. A modest amount of testing would seem to be able to answer this question to your own satisfaction - no?
I would just have the StoredProc return the data set, or multiple data sets, and just build the XML the way you need it via CF.
I've never needed to use CLOB. I almost always stick to the varchar datatype, and it seems to do the job just fine.
There are also options where you could call the Stored Proc, which triggers MSSQL to generate an actual xml file (not just a string) and simply return you the file name. Then you can use CFFILE action="read" to grab the xml string and parse it accrodingly. Assuming your web server and db have a common file storage area.

SQL Server 2005 - How do I convert image data type to character format

Background: I am a software tester working with a test case management database that stores data using the deprecated image data type. I am relatively inexperienced with SQL Server.
The problem: Character data with rich text formatting is stored as an image data type. Currently the only way to see this data in a human readable format is through the test case management tool itself which I am in the process of replacing. I know that there is no direct way to convert an image data type to character, but clearly there is some way this can be accomplished, given that the test case management software is performing that task. I have searched this site and have not found any hits. I have also not yet found any solutions by searching the net.
Objective: My goal is to export the data out of the SQL Server database into an Access database There are fewer than 10,000 rows in the database. At a later stage in the project, the Access database will be upsized to SQL Server.
Request: Can someone please give me a method for converting the image data type to a character format.
.
You presumably want to convert to byte data rather than character. This post at my blog
Save and Restore Files/Images to SQL Server Database might be useful. It contains code for exporting to a byte array and to a file. The entire C# project is downloadable as a zip file.
One solution (for human readability) is to pull it out in chunks that you convert from binary to character data. If every byte is valid ASCII, there shouldn't be a problem (although legacy data is often not what you expect).
First, create a table like this:
create table Nums(
n int primary key
);
and insert the integers from 0 up to at least (maximum image column length in bytes)/8000. Then the following query (untested, so think it through) should get your data out in a relatively useful form. Be sure whatever client you're pulling it to won't truncate strings at smaller than 8000 bytes. (You can do smaller chunks if you want to be opening the result in Notepad or something.)
SELECT
yourTable.keycolumn,
Nums.n as chunkPosition,
CAST(SUBSTRING(imageCol,n*8000+1,8000) AS VARCHAR(8000)) as chunk
FROM yourTable
JOIN Nums
ON Nums.n <= (DATALENGTH(yourTable.imageCol)-1)/8000
ORDER BY yourTable.keycolumn, Nums.n

SQL Server 2008 Full Text Search results

I''ve a little problem while using SQL Server Full Text Search.
Let me explain,
I've a table with a BLOB inside (a PDF file).
I've created the full text index in that table like it should be.
I've the PDF iFilter from Adobe.
BUT, when I put some files in my table and execute a search like:
SELECT *
FROM MyTable
WHERE FREETEXT(*, N'thank');
It only returns the columns from my table (well, that's what I asked, right?).
But I wanted to return the sentence where the word 'thank' was found.
Is there any way to do this?
I've been fighting with this issue for almost 2 days...
Do you have any evidence that the PDF IFilter is working from within SQL Server at all?
Just as a test put an MS Word 2003 doc in there and see if it gets indexed properly.

Resources