Sql server 2008 是否有人将经典ASP与SQL Server 2008及其';什么是新的文件流功能?

Sql server 2008 是否有人将经典ASP与SQL Server 2008及其';什么是新的文件流功能?,sql-server-2008,asp-classic,filestream,Sql Server 2008,Asp Classic,Filestream,我正准备使用SQLServer2008的文件流功能,但我不确定Classic ASP是否可以从SQLServer2008文件流进行读写。我们仍然有一个旧的应用程序,我们想更新,以支持文件上传到数据库,并愿意考虑文件流。如果需要,我可以通过.NET构建一个COM对象来处理这个问题,但我想知道是否有更好的方法,谢谢 下面是一些示例代码。我没有试过,但从以下渠道获得: +1用于查找,但在我将其标记为“答案”之前,您需要先尝试一下 Function Download_File(SQL_Txt As St

我正准备使用SQLServer2008的文件流功能,但我不确定Classic ASP是否可以从SQLServer2008文件流进行读写。我们仍然有一个旧的应用程序,我们想更新,以支持文件上传到数据库,并愿意考虑文件流。如果需要,我可以通过.NET构建一个COM对象来处理这个问题,但我想知道是否有更好的方法,谢谢

下面是一些示例代码。我没有试过,但从以下渠道获得:


+1用于查找,但在我将其标记为“答案”之前,您需要先尝试一下
Function Download_File(SQL_Txt As String, Conn As ADODB.Connection, FieldName As String, Fname As String, Optional FPath As String = "") As String
        Dim Z As Variant, I As Long, Fn As String, Max As Long, X As New ADODB.Recordset, Fx As New FileSystemObject
        Dim FieldType As ADODB.DataTypeEnum
        Const Delta = 32768
        On Error GoTo Download_File_Err
        I = 1
        Download_File = ""


        X.CursorLocation = adUseServer
        X.Open SQL_Txt, Conn, adOpenStatic, adLockReadOnly

        Max = X(FieldName).ActualSize
        FieldType = X(FieldName).Type
        If FieldType = adLongVarChar Then
            Z = X(FieldName).GetChunk(Delta) 'Legggi la porzione di file...
        Else
            'FieldType =adLongVarBinary ->sicuramente!
            Z = BinaryToString(X(FieldName).GetChunk(Delta))
        End If
        'Apri-Crea il nuovo file e scrivi la prima porzione di file...
        Fx.OpenTextFile(Fn, ForWriting, True).Write Z
        While Len(Z) > 0
            If FieldType = adLongVarChar Then
                Z = Nz(X(FieldName).GetChunk(Delta), "")
            Else
                Z = BinaryToString(X(FieldName).GetChunk(Delta))
            End If
            'Salva la porzione di file...
            Fx.OpenTextFile(Fn, ForAppending, False).Write Z
            I = I + 1
        Wend
        X.Close
        Set Fx = Nothing
        Msg
        Download_File = Fn 'Segnala avvenuto scaricamento del file con nome e percorso...
        Exit Function
        Download_File_Err:
            MsgBox Err.Description
            Msg
            X.Close
        Set Fx = Nothing
End Function

Public Function Upload_File(SQL_Txt, Conn As ADODB.Connection, FieldName As String, Optional FPath_and_Name As String = "") As String
        Dim Z As String, L As Long, Fx As New FileSystemObject, X As New ADODB.Recordset
        Dim FieldType As ADODB.DataTypeEnum
        Const Delta = 16384
        On Error GoTo Upload_File_err
        Upload_File = ""
        L = FileLen(FPath_and_Name)
        'In questo caso si usa il cursore lato server... (Ma perchè il cursore lato client fallisce?)
        X.CursorLocation = adUseServer
        X.Open SQL_Txt, Conn, adOpenDynamic, adLockOptimistic
        FieldType = X(FieldName).Type
        If FieldType = adLongVarChar Then
            'Leggi tutti i caratteri dal file...
            Z = Fx.OpenTextFile(FPath_and_Name, ForReading).Read(L)
            X.Update FieldName, Z
        Else
            Z = Fx.OpenTextFile(FPath_and_Name, ForReading).Read(L)
            X.Update FieldName, StringToBinary(Z)
        End If
        X.Close
        Msg
        Upload_File = FPath_and_Name
        Exit Function
        Upload_File_err:
            MsgBox Err.Description
            X.Close
            Msg
End Function

Function BinaryToString(ByteArray As Variant) As String
        '--- Fast Converts the binary content to text
        'Antonin Foller, http://www.motobit.com
        Dim X As New ADODB.Recordset, L As Long
        BinaryToString = ""
        If IsNull(ByteArray) Then Exit Function
        L = LenB(ByteArray)
        If L > 0 Then
            X.Fields.Append "mBinary", adLongVarChar, L
            X.Open
            X.AddNew
            'In questo caso particolare AppendChunk converte l'array di byte
            'in stringa! fantastico.
            X("mBinary").AppendChunk ByteArray
            X.Update
            BinaryToString = X("mBinary")
        End If
        X.Close
End Function

Function StringToBinary(S As String) As Variant
        'Converts the string into a Binary array()
        'Standard conversion...
        Dim I As Long, V As Variant
        StringToBinary = Null
        If S = "" Then Exit Function
        ReDim V(0 To Len(S) - 1) As Byte
        For I = 1 To Len(S)
            V(I - 1) = Asc(Mid(S, I, 1))
        Next I
        StringToBinary = V
End Function