Earlier this week I downloaded the 2008 Visual C# Express Edition with the idea of porting an ancient paradox for dos application to .net. One of the decisions to make is the database. Express Edition comes with something called SQL Server Compact Edition(SQLCE). Apparently this is a Windows CE product ported to the rest of the Windows family. Unfortunately it is not completely compatible with it's larger siblings.
I have a csv like export file from the paradox tables. I was hoping for an easy way to load this into SQLCE . I finally got the data for one table loaded but it wasn't trivial. I'm considering switching to something like mysql just to avoid headaches like this. We'll see.
I made several attempts using the built in data facilities in the IDE. I wrote a quick cpython program to convert the .csv file into properly formatted sql inserts. I also wrote a quick custom c# program to let me execute sql pasted into a textbox and had no luck there for two reasons.
- SQLCE does not like to execute multiple SQL statements at once ie no 'INSERT foo; INSERT bar;' each statement needs to be executed seperately.
- I could not get my statements to insert unless I explicitly put NULL in any field where there was not a value to be inserted
I've always enjoyed python programming and one of the things I've wanted to check out about .net is IronPython. So, I got the 2.0 Alpha8 release (alpha!) and wrote a quick bit of code in the interactive shell to load the data. Here is the cut and pasted code so no brickbats for bad formatting:
>>> import clr>>> cmd = SqlCeCommand()
>>> clr.AddReference('System.Data.SqlServerCe')
>>> from System.Data.SqlServerCe import *
>>> conn = SqlCeConnection()
>>> conn = SqlCeConnection.setConnectionString("Data Source=database.sdf")
>>> cmd.Connection = conn
>>> conn.Open()
>>> inp = open("C:\\newMsSqlAccount.sql","r")
>>> for line in inp:
... cmd.CommandText = line
... rows = cmd.ExecuteNonQuery();
... print rows
And that was it, 26k rows loaded in less than a minute. I am somewhat happier now.
1 comment:
Hey Ken! Welcome to the blog-o-sphere!
Post a Comment