Hello!
I have a SQL Server database with gif images stored in a nText field as
binary. I've been asked to export these images to actual gif files
(about 250 of them). I found a stored procedure that was using some ADO
and it would write a small part of the image correctly and then the
rest was a mess. I was told to check out the ADO and VB groups to see
if anyone knows of a solution for this.
Does anyone have any resources or examples you could point me to? I've
never used ADO before and I've used little VB.
Thanks,
--
Jerry 10 6942
I would never store a gif in a database. Store the image in a folder
and record the location in the database.
I wouldn't store an image in a database either. The images are already
stored in the database and I'm the lucky one who inherited the issue.
--
Jerry
On 28 Apr 2006 08:59:03 -0700, "Jerry" <je*******@gmai l.com> wrote:
¤ Hello!
¤
¤ I have a SQL Server database with gif images stored in a nText field as
¤ binary. I've been asked to export these images to actual gif files
¤ (about 250 of them). I found a stored procedure that was using some ADO
¤ and it would write a small part of the image correctly and then the
¤ rest was a mess. I was told to check out the ADO and VB groups to see
¤ if anyone knows of a solution for this.
¤
¤ Does anyone have any resources or examples you could point me to? I've
¤ never used ADO before and I've used little VB.
¤
See if the following helps. I'm assuming they are not stored as OLE Objects.
How To Read and Write BLOBs Using GetChunk and AppendChunk http://support.microsoft.com/default.aspx/kb/194975
Paul
~~~~
Microsoft MVP (Visual Basic)
The ntext data type is used to store unicode text. If someone has stored
binary data in such a field you need to know exactly how it is stored in
order to retreive it correctly.
Jerry wrote: Hello!
I have a SQL Server database with gif images stored in a nText field as binary. I've been asked to export these images to actual gif files (about 250 of them). I found a stored procedure that was using some ADO and it would write a small part of the image correctly and then the rest was a mess. I was told to check out the ADO and VB groups to see if anyone knows of a solution for this.
Does anyone have any resources or examples you could point me to? I've never used ADO before and I've used little VB.
Thanks,
I was able to see the upload code this morning.
<%
'this is the code block that breaks apart the image and turns it into
blob data
If Request.TotalBy tes <>0 Then
BlobSize = Request.TotalBy tes
BlobData = Request.BinaryR ead( BlobSize )
bnCRLF = chrB( 13 ) & chrB( 10 )
Divider = LEFTB( BlobData, INSTRB( BlobData, bnCRLF ) - 1 )
BlobDataStart = INSTRB( BlobData, bnCRLF & bnCRLF ) + 4
BlobDataEnd = INSTRB( BlobDataStart + 1, BlobData, divider ) -
BlobDataStart
strPicture= MIDB( BlobData, BlobDataStart, BlobDataEnd )
Session("Pictur e")= strPicture
'this is the original record set
set rsBLOB = Server.CreateOb ject("ADODB.Rec ordset")
rsBLOB.ActiveCo nnection = CON_STRING
rsBLOB.Source = "SELECT * FROM tblblob"
rsBLOB.CursorTy pe = 2
rsBLOB.CursorLo cation = 2
rsBLOB.LockType = 3
rsBLOB.Open()
rsBLOB_numRows = 0
'add a new record
rsBLOB.Addnew
rsBLOB("Blob_ph oto").AppendChu nk strPicture
rsBLOB("Blob_ph otoYesNo") = "88" 'the 1 turns the camera image on
rsBLOB("Blob_bs ize") = BlobSize 'put the size into the db
rsBLOB.update
rsBLOB.close
End If
%>
--
Jerry
I found a solution.
CREATE PROCEDURE ntext2file @filename nvarchar(128), @table
nvarchar(128),@ column nvarchar(128), @where nvarchar(4000)
--Saves text from an Ntext column to a file
AS
IF (@filename is NULL) OR (@table is NULL) OR (@column is NULL) OR
(@where is NULL)
BEGIN
PRINT 'saveNtext2file saves text from an Ntext column to a file'
PRINT 'Usage:'
PRINT 'EXEC saveNtext2file FileName, tableName, columnName,
WhereCondition'
PRINT ''
PRINT 'For example: EXEC ntext2file ''C:\test.txt'' , ''customers'',
''memo'', ''where customerID=234' ''
RETURN
END
DECLARE @hr int,@fso int,@i int, @j int, @blocks int, @c int, @buffer
varbinary(1000) , @sql nvarchar(4000)
EXEC @hr = sp_OACreate 'ADODB.Stream', @fso OUT
exec @hr = sp_oasetpropert y @fso, 'Type', 1--adTypeBinary=1
EXEC @hr = sp_OAMethod @fso, 'Open'
set @sql = N'SELECT @c =(select DATALENGTH('+@c olumn+')/2 from
'+@table+' '+@where+')'
exec sp_executesql @sql, N'@c int OUTPUT', @c OUTPUT
set @j=0
create table #t ( t ntext )
SET @i=@c
--read 1000 bytes at a time
WHILE @i > 500
BEGIN
insert into #t
exec getREADTEXT @column,@table, @where,@j,500
set @buffer=(select convert(varbina ry(1000),conver t(nvarchar(500) ,t))
from #t)
EXEC @hr = sp_oasetpropert y @fso, 'Write', @buffer
delete #t
SET @i=@i-500
SET @j=@j+500
END
--read remaining bytes
if @i > 0
BEGIN
insert into #t
exec getREADTEXT @column,@table, @where,@j,@i
set @buffer=(select convert(varbina ry(1000),conver t(nvarchar(500) ,t))
from #t)
EXEC @hr = sp_oasetpropert y @fso, 'Write', @buffer
delete #t
END
drop table #t
EXEC @hr = sp_oasetpropert y @fso, 'SaveToFile', @filename
EXEC @hr = sp_OAMethod @fso, 'Close'
GO
Can I get the code for "getREADTEX T "
Thanks!
Sorry about that. Here it is!
CREATE PROCEDURE getREADTEXT @column nvarchar(128), @table
nvarchar(128),@ where nvarchar(4000), @position int,@length int
--given a column, table and filter clause plus a position to start
reading the text and length to be read, the selected portion of the
text will be returned
AS
declare @sql nvarchar(4000)
set @sql='declare @txtPtr varbinary(16)
select @txtPtr = TEXTPTR('+@colu mn+') from '+@table+' '+@where+
' READTEXT '+@table+'.'+@c olumn+' @txtPtr '+str(@position )+'
'+str(@length)+ ''
exec(@sql)
GO
Thanks!
I have it looping through several thousand records and it stops spitting out
files after 256. Do you have any idea why? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bryan Russell |
last post by:
Hi,
My asp/sql server application gets an error, but only when you use the
Excel export option:
<% Response.ContentType="application/vnd.ms-excel" %> (very popular w/
users)
I think somebody entered a string of characters that Excel does not
like
|
by: Bill |
last post by:
Hi all,
I have an asp page that writes to an ntext field in SQL Server 2000.
All was going well until I had to put in a section of text greater than 8000
bytes.
Then I got a timeout error and the update wouldn't go through.
After reading that 2000 only accepts chunks of 8000 bytes or under at a
time, I attempted to use the AppendChunk method.
The code I wrote seems to work first time I enter text in the page, no
matter how big. But...
|
by: Matik |
last post by:
Hello to all,
Below the sample code:
declare @arg_szMsgText ntext
set @arg_szMsgText = isnull(@arg_szMsgText, N'unknown message')
Now the error message I get:
"The assignment operator operation cannot take a ntext data type as an
|
by: Sileesh |
last post by:
HI
I know this is not the right forum to post this question, but i think some
one might have a suggestion.
I have a Table "Test" with columns
Id bigint (PK), Number Varchar(50), Notes ntext. in sql server 2000
I ahve a stored procedure in which i am trying to insert the same data as
new record with column "Number" changed.
|
by: Igor |
last post by:
Is there a way to transfer ntext data from one table to another?
I tried this
UPDATE
SET = (SELECT FROM WHERE
=1)
WHERE = 1;
| |
by: =?Utf-8?B?ZGF2aWQ=?= |
last post by:
I try to follow Steve's paper to build a database, and store a small text
file into SQL Server database and retrieve it later. Only difference between
my table and Steve's table is that I use NTEXT datatype for the file instead
of using IMAGE datatype. I can not use SqlDataReader to read the data. I need
your help, Thanks.
-David
(1) I have a table TestFile for testing:
ID int
FileName navrchar(255)
|
by: JHNielson |
last post by:
I have a somewhat simple question, but have been baffled by it for a while, and now I'm on a tight deadline - have to get it done within 24 hours.
I am trying to export a set of files to my hard drive to then later be FTPd to a server. the file format should be "TITLE.yyyymmdd" where yymmdd is the date code for when the files are created.
The files can't be .txt. But when I run the files as ".txt" the code runs just fine. when I...
|
by: verb13 |
last post by:
I am running this query to an sql server 2000 database from my asp
code:
"select * from MyTable where
MySqlServerRemoveStressFunction(MyNtextColumn) = '" &
MyAdoRemoveStressFunction(MyString) & "'"
The problem is that the replace function doesn't work with the ntext
datatype (so as to replace the stresses with an empty string). I had
to implement the MySqlServerRemoveStressFunction, i.e. a function that
takes a column name as a...
|
by: felciano |
last post by:
Hi --
Is there a standard way to use the csv module to export data that
contains multi-line values to Excel? I can get it mostly working, but
Excel seems to have difficulty displaying the generated multi-line
cells.
The following reproduces the problem in python 2.5:
import csv
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |