0

I am trying to store a video file in Base64String format. When I try it in my local database it takes around 15 seconds to complete the insert. But when I try it on a hosted database it takes forever to execute the line:-

    cmd.ExecuteNonQuery();

The upload completes but I am stuck in this line like forever. The file size is about 26mb. I am converting the file to byte array and then converting it to Base64String.

Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116
  • Which dbms do you use? SQL Server? – Roman Marusyk Sep 10 '15 at 18:50
  • I am using MSSql sever database – Soham Krishna Sep 10 '15 at 18:53
  • 1
    Why are you using base64 to store it? You should really be using varbinary(max) assuming this is Sql Server. This is much more efficient than using varchar/nvarchar to store a converted value. It would be like persisting dates as strings, or numbers as strings. The various Database data types exist for a good reason. – Igor Sep 10 '15 at 18:54
  • If you have large files I would recommend to store these files in the filesystem, and save relative paths to these files to your database. Have a setting with the path to the main folder, where you are going to store files. And add relative path to this main folder path upon calculating the real path to a file. Also check [this post](http://stackoverflow.com/questions/16543810/store-file-on-file-system-or-as-varbinarymax-in-sql-server) –  Sep 10 '15 at 19:00
  • 1
    Also sending 26MB across the network, but as a string so probably larger now than the original 26MB, can take time depending on your network. Locally it will always run fast because it all executes on the same machine so less boundaries you are dealing with. You also don't mention the type of network that you have to cross from source machine to target machine (db server), for all we know from the description this is over a VPN or maybe in a different country or on some over allocated cloud server or a machine with 1 GIG RAM. At this point the possibilities are endless all we can do is guess. – Igor Sep 10 '15 at 19:00
  • 2
    26M * 8/5 (for base64) * 2 (Unicode strings) - about 82M - decent amount of traffic, especially to send over non-private shared network – Alexei Levenkov Sep 10 '15 at 19:02
  • I am using varBinary datatype to store the file, but still it seems to take like forever to insert into database – Soham Krishna Sep 11 '15 at 18:07

0 Answers0