473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

best practice for loading large files into SQL Server database

Hello,

I am working on a peice of code that takes a file and loads it into a SQL
Server DB.

When I load large files (over 70Mb) I get a system out of memory exception.
My machine has 2G RAM

I think the problem is that a file stream pointing to the file on the file
system is loaded into a memory stream one byte at a time. Does anybody have
any pointers on doing this type of thing and how to do this so that the file
is actually streamed from the file system right into the SQL Server DB?

Any advice or links to articles on how to do this best etc would be really
appreciated.

Thanks in advance for any help

--
Regards,

Phil Johnson (MCAD)
Nov 23 '07 #1
4 6651
Well, what is the file and what code are you using to look at it?

To insert lots of rows (i.e. a huge CSV) you should be using
SqlBulkCopy with a streaming IDataReader; I recommend the one here:
http://www.codeproject.com/cs/database/CsvReader.asp

To insert a single huge BLOB, you must use chunking techniques - i.e.
you need to allocate a buffer (8040 bytes is optimal for SQL Server, I
believe) and read buffer-fulls of info, and pass this down to the db
in chunks, using the appropriate BLOB SQL commands [the commands
change between SQL 2000 with "image", and SQL 2005 with
"varbinary(max)"].

If you try and load the entire BLOB into memory (as a huge byte[]),
yes it will fail.

If you try and load the entire file into memory (as a DOM, DataTable,
etc), yes it will fail.

Marc
Nov 23 '07 #2
I found some of my old BLOB examples...

stream=>database
http://groups.google.co.uk/group/mic...4e7e3782e59a93

database=>stream
http://groups.google.co.uk/group/mic...d173f1db2951f1

Marc
Nov 23 '07 #3
Thanks Marc,

It is indeed a BLOB that I am loading, not a csv.

Those links look ideal.

Thanks again.
--
Regards,

Phil Johnson (MCAD)
"Marc Gravell" wrote:
I found some of my old BLOB examples...

stream=>database
http://groups.google.co.uk/group/mic...4e7e3782e59a93

database=>stream
http://groups.google.co.uk/group/mic...d173f1db2951f1

Marc
Nov 23 '07 #4
No problem. If you need fewer round trips when saving, I believe that
any multiple of 8040 will work; likewise, if you are using SQL Server
2005 you should definitely use the varbinary(max) and associated
commands (instead of UPDATETEXT) - but the "read" stays the same.

For info, SQL Server 2008 has a new file-stream data type / attribute
(or something!). I haven't played with it yet, but that may also be
useful for file-based scenarios. YMMV.

Marc
Nov 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: great_googley_moogley | last post by:
Greetings, I am in the process of installing a SQL database at a customer location. I have determined that there are 3 ways to do this, and I wanted to know which is the best of the 3. 1...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
6
by: Sandy | last post by:
Hello - I have a book that illustrates pulling menu items from a Sql Server table into an ascx via a stored procedure. Is this something that is done in the real world? I do like the effect...
0
by: David Helgason | last post by:
I think those best practices threads are a treat to follow (might even consider archiving some of them in a sort of best-practices faq), so here's one more. In coding an game asset server I want...
4
by: Collin Peters | last post by:
I have searched the Internet... but haven't found much relating to this. I am wondering on what the best practices are for migrating a developmemnt database to a release database. Here is the...
5
by: Rich | last post by:
Hello, I have a search application to search data in tables in a database (3 sql server tables). I populate 2 comboboxes with with data from each table. One combobox will contain unique...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
7
by: =?Utf-8?B?TW9iaWxlTWFu?= | last post by:
Hello everyone: I am looking for everyone's thoughts on moving large amounts (actually, not very large, but large enough that I'm throwing exceptions using the default configurations). We're...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.