Re: Uploading Large File to SQL

From: - Steve - (sevans_at_foundation.sdsu.edu)
Date: 07/13/04


Date: Tue, 13 Jul 2004 10:45:56 -0700

Okay that fixed the problem. However now when I'm upload a 500+mb file I run out of memory on the web server. Is there a better way to do this where I can stream the data in instead of creating such a huge byte[] variable.

-- 
Steve Evans
Email Services
SDSU Foundation
(619) 594-0708
  "Steve C. Orr [MVP, MCSD]" <Steve@Orr.net> wrote in message news:%23NLCZ3PaEHA.712@TK2MSFTNGP11.phx.gbl...
  You can add or modify the following section in your web.config file:
  <configuration>
  <system.web>
  <httpRuntime maxRequestLength="4096" />
  </system.web>
  </configuration>
  The above value (4096 KB) is the default maximum upload file size.
  -- 
  I hope this helps,
  Steve C. Orr, MCSD, MVP
  http://Steve.Orr.net
    "- Steve -" <sevans@foundation.sdsu.edu> wrote in message news:un7FmBPaEHA.2520@TK2MSFTNGP12.phx.gbl...
    I have the following function that is supposed to save a file to a SQL server.  It works fine when the file is under about 5mb, but bigger than that and after I hit submit (which eventually fires off this function) it get a 400 page error.
    private void btnUpload_Click(object sender, System.EventArgs e)
    {
    HttpPostedFile myFile = fileUpload.PostedFile;
    byte[] myFileData = new byte[myFile.ContentLength];
    myFile.InputStream.Read(myFileData, 0, myFile.ContentLength);
    string fileName = Path.GetFileName(myFile.FileName);
    SaveFileToSQL(fileName, myFile.ContentType, ref myFileData);
    }
    private string SaveFileToSQL(string fileName, string fileType, ref byte[] fileData)
    {
    SqlConnection myConnection = new SqlConnection(<connection details>)
    SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT * FROM FileX", myConnection);
    SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myDataAdapter);
    myConnection.Open();
    DataSet myDataSet = new DataSet();
    myDataAdapter.Fill(myDataSet, "FileX");
    DataTable myDataTable = myDataSet.Tables["FileX"];
    //insert data into SQL
    DataRow myDataRow = myDataTable.NewRow();
    myDataRow["FileName"] = fileName;
    myDataRow["FileSize"] = fileData.Length;
    myDataRow["ContentType"] = fileType;
    myDataRow["FileData"] = fileData;
    myDataTable.Rows.Add(myDataRow);
    myDataAdapter.Update(myDataSet, "FileX");
    myConnection.Close();
    }
    -- 
    Steve Evans
    Email Services
    SDSU Foundation
    (619) 594-0708


Relevant Pages

  • Re: Uploading Large File to SQL
    ... However now when I'm upload a 500+mb file I run out of memory on the web server. ... private string SaveFileToSQL ... SqlDataAdapter myDataAdapter = new SqlDataAdapter ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Inet1 connecting but cant upload - any help appreciated
    ... I am using the Inet control to link to our web server. ... I can upload and download files using MS FrontPage without any trouble. ... Dim strDestinationFile As String ...
    (microsoft.public.vb.general.discussion)
  • Inet1 connecting but cant upload - any help appreciated
    ... I am using the Inet control to link to our web server. ... I can upload and download files using MS FrontPage without any trouble. ... Dim strDestinationFile As String ...
    (microsoft.public.vb.general.discussion)
  • Newbie: Better way to check a magic number on a file?
    ... upload to a Web server. ... Here is the first test - to verify the magic number of the file that I ... I have to unpack my string ...
    (comp.lang.ruby)
  • Re: Http post
    ... Now if you were for example to build a string out of these 3 things ... Two separate HTTP Post request are required to complete the upload ... The example you sent me works fine and the authentication id can be ... perhaps just simple text string with an attachment (in binary format) ...
    (microsoft.public.fox.programmer.exchange)