title: Uploading files to SQL Server without using too much memory
body: <p>I am working with SQL Server 2008 and <code>FileStream</code> data types to save large files in the database.</p>
  
  <p>So far everything is working fine but the problem is my upload method looks like this:</p>
  
  <pre><code>public static void UploadFileToDatabase(string location)
  {
     FileStream fs = new FileStream(location, FileMode.Open, FileAccess.Read);
  
     byte[] data = new byte[fs.Length];
  
     fs.Read(data, 0, System.Convert.ToInt32(fs.Length));
     fs.Close();
  
     SaveToDatabaseMethod(data)
  
     data = null;
  }
  </code></pre>
  
  <p>Obviously I am saving the files in memory and then uploading them to server which I think is a really bad practice so is there anyway I can at least limit the amount of memory needed for this ? </p>
  
  <p>What is the best practice in my case ?</p>