Re: Uploading Large File to SQL

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Joe Fallon (jfallon1_at_nospamtwcny.rr.com)
Date: 07/15/04


Date: Wed, 14 Jul 2004 23:45:10 -0400

There is no simple built in way to do it.
You should buy a 3rd party product if you need that ability.

There is an old thread (that is huge) that discussed this issue for over a year.
They came up with 90% of the code required to do this and then "went quiet".
Then 3rd party controls started being sold.
Coincidence? I think not.

-- 
Joe Fallon
  "- Steve -" <sevans@foundation.sdsu.edu> wrote in message news:eNDKHFQaEHA.2908@TK2MSFTNGP10.phx.gbl...
  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
    ... Yes you need a lot of memory on your web serverif you're going to be dealing with files of that size. ... private string SaveFileToSQL ... SqlDataAdapter myDataAdapter = new SqlDataAdapter ... DataSet myDataSet = new DataSet; ...
    (microsoft.public.sqlserver.programming)
  • Re: Uploading Large File to SQL
    ... You should buy a 3rd party product if you need that ability. ... private string SaveFileToSQL ... SqlDataAdapter myDataAdapter = new SqlDataAdapter ... DataSet myDataSet = new DataSet; ...
    (microsoft.public.sqlserver.programming)
  • Re: Uploading Large File to SQL
    ... private string SaveFileToSQL ... SqlConnection myConnection = new SqlConnection ... SqlDataAdapter myDataAdapter = new SqlDataAdapter ... DataSet myDataSet = new DataSet; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Uploading Large File to SQL
    ... Yes you need a lot of memory on your web serverif you're going to be dealing with files of that size. ... private string SaveFileToSQL ... SqlDataAdapter myDataAdapter = new SqlDataAdapter ... DataSet myDataSet = new DataSet; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Uploading Large File to SQL
    ... private string SaveFileToSQL ... SqlConnection myConnection = new SqlConnection ... SqlDataAdapter myDataAdapter = new SqlDataAdapter ... DataSet myDataSet = new DataSet; ...
    (microsoft.public.sqlserver.programming)