Note that there are some explanatory texts on larger screens.

plurals
  1. POPython and SQL Bulk Insert
    text
    copied!<p>I am using IronPython to create a data array and I need to insert this array to MS SQL Server. The .Net class I'm using is SqlBulkCopy (part of System.Data.SqlClient).</p> <p>I have found this StackOverflow article quite useful <a href="https://stackoverflow.com/questions/3913371/sqlbulkcopy-from-a-list">SqlBulkCopy from a list</a></p> <p>However, since I'm only starting to learn python I'm having difficulties recreating this C# example with Python code.</p> <p>Here's what I have so far</p> <pre><code>import clr clr.AddReference('System.Data') from System.Data import * import clr clr.AddReference('System') from System import * sqlDbConnection = SqlClient.SqlConnection("&lt;my-db-connection-string&gt;") sqlDbConnection.Open() myDataArray = [ [Byte(7), Byte(8), Int32(1), Byte(15), Byte(12), Single(0.34324)], [Byte(5), Byte(1), Int32(2), Byte(11), Byte(10), Single(0.77362)], [Byte(9), Byte(2), Int32(3), Byte(12), Byte(9), Single(0.93394)]] sqlDbConnection.Close() </code></pre> <p>The idea is to generate a large data array (say > 1 Million rows) and import it to my table using bulk copy method. I would really appreciate if anyone could shed a light on this and explain how I could tackle this and how I can make use of all the options that come with the bulk copy class. <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx" rel="nofollow noreferrer">SqlBulkCopy msdn reference</a></p> <p>I have been looking for useful examples in Python but did not find any so far...</p> <p>Much appreciated</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload