ho questo database con una tabella che ha il seguente ma non ho modo di decifrare loMemorizzazione di documenti Microsoft Word 97 nella colonna di SQL Server
DATA, TYPE, FILE TYPE, SIZE, DOC TYPE
0x15234324 , Word.Document.8 ,DOC, 19968, WORD.DOCUMENT.8
Il campo sembra contenere un documento di parola memorizzata in un SQL Server IMAGE
colonna
Qualcuno ha incontrato questo prima o un modo per estrarre questi dati in un formato leggibile?
Finora ho provato a utilizzare PHP per estrarre il file e scriverlo in un documento Word ma non ho avuto molta fortuna.
UPDATE: Ora ho Visual Studio Express e vorrei un modo per estrarre questi dati e salvare in un documento word
UPDATE2: Questo è quello che ho in VB sofar
Imports System.Data.SqlClient
Imports System.IO
Public Class Form1
Private Shared Function RetrieveFile(ByVal filename As String) As Byte()
Dim connection As New SqlConnection("Server=sqlsrv;database=database;Trusted_Connection=Yes;")
Dim command As New SqlCommand("select data from objects where object_ref in (select data from parts where object_ref =239804)", connection)
command.Parameters.AddWithValue("test", filename)
connection.Open()
Dim reader As SqlDataReader = command.ExecuteReader(System.Data.CommandBehavior.SequentialAccess)
reader.Read()
Dim memory As New MemoryStream()
Dim startIndex As Long = 0
Const ChunkSize As Integer = 256
While True
Dim buffer As Byte() = New Byte(ChunkSize - 1) {}
Dim retrievedBytes As Long = reader.GetBytes(1, startIndex, buffer, 0, ChunkSize)
memory.Write(buffer, 0, CInt(retrievedBytes))
startIndex += retrievedBytes
If retrievedBytes <> ChunkSize Then
Exit While
End If
End While
connection.Close()
Dim data As Byte() = memory.ToArray()
memory.Dispose()
Return data
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "Doc File|*.doc"
saveFileDialog1.Title = "Save an doc File"
saveFileDialog1.ShowDialog()
If saveFileDialog1.FileName <> "" Then
Dim fs As New System.IO.FileStream(saveFileDialog1.FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)
Dim data As Byte() = RetrieveFile("test.doc")
fs.Write(data, 0, data.Length)
fs.Flush()
fs.Close()
End If
End Sub
End Class
Si potrebbe probabilmente solo memorizzare i byte contenuti nel 'data' nel file system e quindi apri quel file con MS Word. –
Cool - come si estraebbero questi dati dal server SQL? come le stringhe devono essere troppo corte nella finestra dei risultati della query managment SQL – Rob
Sì, SSMS troncerà sempre a max. lunghezza: è necessario utilizzare del codice per recuperarlo da SQL Server. Vedi questa [altra domanda SO] (http://stackoverflow.com/questions/2818557/are-there-any-utilities-to-extract-binary-data-from-sql-server) su un argomento simile - forse quello Ti aiuterò a –