From what I have been told, there is no getchunk in ADO.net so that adds to
the issue. I used the appendchunk and getchunk in my VB6 app with DAO and
that works great. But with no getchunk in ADO.net, I am guessing the code I
am using in VB.NET 2003 does not record the file the same way as if I use
getchunk.
In VB6 for reading from the database, the code I used is (I already have a
recordset to the correct record):
Dim NumBlocks As Integer, DestFile As Integer, i As Integer
Dim FileLength As Long, LeftOver As Long
Dim FileData As String
' Get the size of the field.
FileLength = rsQuestions.Fields("SoundBite").FieldSize()
If FileLength = 0 Then
Exit Sub
End If
' Calculate number of blocks to write and leftover bytes.
NumBlocks = FileLength \ BlockSize
LeftOver = FileLength Mod BlockSize
' Remove any existing destination file.
DestFile = FreeFile
Open "Temp2.mp3" For Output As DestFile
Close DestFile
' Open the destination file.
Open "Temp2.mp3" For Binary As DestFile
' Write the leftover data to the output file.
FileData = rsQuestions.Fields("SoundBite").GetChunk(0, LeftOver)
Put DestFile, , FileData
' Write the remaining blocks of data to the output file.
For i = 1 To NumBlocks
' Reads a chunk and writes it to output file.
FileData = rsQuestions.Fields("SoundBite").GetChunk((i - 1) *
BlockSize _
+ LeftOver, BlockSize)
Put DestFile, , FileData
Next i
Close DestFile
The only thing I can think of is that the code above is recording the file
differently than the following code that I have tried in VB.net but I am not
sure what I need to change in the following vb.net code to get the same
results:
Dim SystemConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & strFileName & ";User ID=Admin;Jet " _
& "OLEDB:Database Password=****"
Dim cn As New System.Data.OleDb.OleDbConnection(SystemConnString )
cn.Open()
Dim cmd As New System.Data.OleDb.OleDbCommand("SELECT SoundBite from "
& strTableName & " where [QuestionNumber] = " & CurrentQuestion, cn)
Dim dr As System.Data.OleDb.OleDbDataReader = cmd.ExecuteReader
dr.Read()
Dim b(dr.GetBytes(0, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
dr.GetBytes(0, 0, b, 0, b.Length)
dr.Close()
cn.Close()
Dim fs As New System.IO.FileStream("SoundBite.mp3", IO.FileMode.Create,
IO.FileAccess.Write)
fs.Write(b, 0, b.Length)
fs.Close()
dr.Close()
cn.Close()
Any ideas? Is there any way I can adjust the vb.net code with ado.net to be
able to replicate what the code in vb6 does even though there is no getchunk
function? Or with the way I am attempting to save the data in ado.net to a
file, is there a way to replicate this functionality in a vb6 program using
DAO with or without getchunk?
I have been searching the internet for a solution for the last couple of
days and no luck. The only solutions listed for Blob data in vb6 is to use
appendchunk and everything listed for vb.net shows what I just posted or
something similar with the message that getchunk and appendchunk are not
available in ado.net. So I am out of ideas as to why the .net code results
in a file that is double the size of what was originally recorded and then
doesn't work in any audio player like media player.
If you have any other ideas, information, links, anything, please reply.
Mark
"Paul Clement" wrote:
I believe the counterpart to the KB article you posted would be the AppendChunk/GetChunk methods. So
for example, if you saved the file using AppendChunk and ADO (or DAO) you should be able to retrieve
the file using the code from the KB article you posted.
Paul
~~~~
Microsoft MVP (Visual Basic)