Saturday, July 30, 2011

SQL Server Bulk Import Script

Nice easy copy and paste SQL Server bulk import script:


CREATE DATABASE databasename
USE databasename


CREATE TABLE tablename
(
        id     int
,       col2      date
,       col3     float
)


BULK INSERT tablename
FROM 'C:\datalocation\filename.csv'
WITH
(
MAXERRORS = 0,
FIRSTROW = 2, -- i.e. 2 if has a header row on line 1
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)

Tuesday, July 12, 2011

python SimpleHTTPServer solves XMLHttpRequest errors

Loading an html file in a browser from the filesystem (i.e. file:///) that uses XMLHttpRequest will throw a javascript error since for security purposes file:/// requests have a null origin.

Example error:
XMLHttpRequest cannot load file:///somepath. Origin null is not allowed by Access-Control-Allow-Origin.

The solution is to serve the html file using http from a local webserver.  A very easy and simple webserver to run is offered with python by typing this in the folder you want to serve files from:
python -m SimpleHTTPServer 1234

Then navigate to http://127.0.0.1:1234/somepath to view the file.