SqlBulkCopy from a List

With FastMember, you can do this without ever needing to go via DataTable (which, in my tests, more-than-doubles the performance): using(var bcp = new SqlBulkCopy(connection)) using(var reader = ObjectReader.Create(data, “Id”, “Name”, “Description”)) { bcp.DestinationTableName = “SomeTable”; bcp.WriteToServer(reader); } Note that ObjectReader can also work with non-generic sources, and it is not necessary to specify the … Read more

Bulk Insert to Oracle using .NET

I’m loading 50,000 records in 15 or so seconds using Array Binding in ODP.NET It works by repeatedly invoking a stored procedure you specify (and in which you can do updates/inserts/deletes), but it passes the multiple parameter values from .NET to the database in bulk. Instead of specifying a single value for each parameter to … Read more

mongodb: insert if not exists

Sounds like you want to do an “upsert”. MongoDB has built-in support for this. Pass an extra parameter to your update() call: {upsert:true}. For example: key = {‘key’:’value’} data = {‘key2′:’value2’, ‘key3′:’value3’}; coll.update(key, data, upsert=True); #In python upsert must be passed as a keyword argument This replaces your if-find-else-update block entirely. It will insert if … Read more

Bulk Insert Partially Quoted CSV File in SQL Server

Unfortunately SQL Server interprets the quoted comma as a delimiter. This applies to both BCP and bulk insert . From http://msdn.microsoft.com/en-us/library/ms191485%28v=sql.100%29.aspx If a terminator character occurs within the data, it is interpreted as a terminator, not as data, and the data after that character is interpreted as belonging to the next field or record. Therefore, … Read more