Upload - large files to MS SQL Server using a HexString property and UPDATETEXT SQL statement

          Sample for ScriptUtils.FormField.HexString 

Examples
Upload - large files to MS SQL Server using a HexString property and UPDATETEXT SQL statement 
<%
'Sample file db-HexStringChunk.asp 
'Upload to MS SQL database, store file using HexString method and UPDATETEXT command
'Suitable for upload of big files (up to 2GB) 
'   and MS SQL databse (MS SQL 6.5 - MS SQL 2000)
'see article 'To database, or not to database?' in HugeASP upload help

Server.ScriptTimeout = 36000

'Upload large files to MS SQL Server using HexString
Dim d: D="" & time: d=Replace(d,":","")

Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")

'was the Form successfully received?
If Form.State = 0 Then
  Dim Conn, SQL, RS, UploadID
  'Open connection to database
  Set Conn = GetConnection 

	'Create insert statement with empty Data field
  SQL = "SET NOCOUNT ON Insert into Upload(UploadDT, ContentType, SouceFileName, Title, [Description], Data) values("
  SQL = SQL & "GetDate()"
  SQL = SQL & ", '" & Form("DBFile").ContentType & "'"
  SQL = SQL & ",  '" & Form("DBFile").FileName & "'"
  SQL = SQL & ",  '" & Form("Title") & "'"
  SQL = SQL & ",  '" & Form("Description") & "'"
  SQL = SQL & ",0x)" & vbCrLf
  SQL = SQL & "Select @@IDENTITY as UploadID"
  

  Set RS = Conn.Execute(SQL)
    UploadID = RS("UploadID")
  RS.Close


  'Set block size to 1MB
  Const BlockSize = &H100000

  'Process source data using blocks
  Dim BlockCounter, HexDataBlock
  For BlockCounter = 0 To Form("DBFile").Length Step BlockSize

    'Get a part of source data as a Hex string
    HexDataBlock = Form("DBFile").HexString(BlockCounter, BlockSize)

    'Add a part of source data to the field
    SQL = "DECLARE @dataptr binary(16)" & vbCrLf
    SQL = SQL & "SELECT @dataptr = TEXTPTR(Data)"
    SQL = SQL & " FROM Upload WHERE UploadID=" & UploadID & vbCrLf
    SQL = SQL & "UPDATETEXT Upload.Data @dataptr " & BlockCounter & " NULL 0x" & HexDataBlock
    Conn.Execute SQL
  Next 'BlockCounter 
  '

  Conn.Close
End If'Form.State = 0 then

Function GetConnection1()
  Dim Conn: Set Conn = CreateObject("ADODB.Connection")
  Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
  Conn.open "Data Source=D:\Temp\upload.mdb"
  Conn.CommandTimeout = 1800
  'Conn.open "Data Source=" & Server.MapPath("upload.mdb") 
	Set GetConnection = Conn
End Function

Function GetConnection()
  Dim Conn: Set Conn = CreateObject("ADODB.Connection")
  Conn.Provider = "SQLOLEDB"
  Conn.open "Data Source=(local);Database=Upload", "sa", ""
  'Conn.open "Data Source=" & Server.MapPath("upload.mdb") 
	Set GetConnection = Conn
End Function

Function CreateUploadTable(Conn)
  'This function creates upload table for MSSQL 6.5/7.0
  Dim SQL
  SQL = SQL & "CREATE TABLE Upload ("
  SQL = SQL & "	UploadID int IDENTITY (1, 1) NOT NULL ,"
  SQL = SQL & "	UploadDT datetime NULL ,"
  SQL = SQL & "	RemoteIP char (15) NULL ,"
  SQL = SQL & "	ContentType char (64) NULL ,"
  SQL = SQL & "	SouceFileName varchar (255) NULL ,"
  SQL = SQL & "	Title varchar (255) NULL ,"
  SQL = SQL & "	Description text NULL ,"
  SQL = SQL & "	Data image NULL "
  SQL = SQL & ")"
  Conn.Execute SQL
End Function

%>  
<br>Upload To MS SQL database, store file using HexString method And UPDATETEXT command
<br>sample For <A Href=http://www.motobit.com>HugeASP upload</A>
<br>Suitable For upload of big files (up To 2GB) And MS SQL databse (MS SQL 6.5 - MS SQL 2000)
<br>see article 'To database, or not to database?' in HugeASP upload help

<Table><form method=post ENCTYPE="multipart/form-data">
<TR>
 <TD></TD>
 <TD Align=Right><input type="submit" Name="Action" value="Upload the file >>"></TD>
</TR>
<TR>
 <TD>File To upload</TD>
 <TD><input type="file" name="DBFile"></TD>
</TR>
<TR>
 <TD>Title</TD>
 <TD><input size="60" name="Title" value="Title of the file."></TD>
</TR>
<TR>
 <TD>Description</TD>
 <TD><textarea cols="60" rows="8" name="Description">Type description of the file.</textarea></TD>
</TR>

</form></Table>
  Other links for Upload - large files to MS SQL Server using a HexString property and UPDATETEXT SQL statement
One form field. Member of FormFields collection.
      Easy to use, hi-performance ASP file upload component with progress bar indicator. Let's you upload multiple files with size up to 2GB to a disk or database along with another form fields. Works with large posts, any character set (including unicode utf-8). Contains one-click multiple files/folders download with on-the-fly compression (Using BinaryWrite/BinaryRead).
      Hi-performance text file logging for ASP/VBScript/VBA applications. Lets you create daily/weekly/monthly log files with variable number of logged values and extra timing and performance info.
       Lets you work with safearray binary data in VBS/JS. It also enables conversion between binary and String data using several code pages. ZLib compress and uncompress functions. Lets you transfer files using compressed stream from a client to server using IE.
      This library also enables calling of some Kernel and Advapi functions (performance, timing, sleep, configuration ...) and enables native work with INI files.


© 1996 – 2005 Motobit Software, help{at}pstruh.cz, help v. 2.16.14