HDBC-ODBC under Windows

From HaskellWiki
Revision as of 17:45, 1 September 2006 by Spookylukey (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

A brief description of how to get HDBC-ODBC working under windows, for connecting to things like MS SQL server.


  • Ensure your path contains the ghc bin directory:
    • Right click on My Computer, select Properties -> Advanced -> Environment variables -> change the variable 'Path'
  • Follow the README instructions for installing hdbc
  • Follow the README instructions for installing hdbc-odbc, with these changes:
    • The include-dirs line should be changed to:
      include-dirs: . "C:\\Program Files\\Microsoft Data Access SDK 2.8\\Libs\\x86"
    • Do the following at a command prompt, with the hdbc-odbc directory being current directory:
  ghc --make -o setup Setup.hs
  setup configure
  setup build
  setup install

You may need other ODBC drivers, but often they will be installed already on a development box that has the database server installed.


You can test it from a ghci prompt (obviously you'll need to change the connection string and query):

Prelude> :m Database.HDBC
Prelude Database.HDBC> :m + Database.HDBC.ODBC
Prelude Database.HDBC Database.HDBC.ODBC> let connectionString =  "Driver={SQL Server};Server=myserver;Database=mydatabase;Trusted_Connection=yes;"
Prelude Database.HDBC Database.HDBC.ODBC> let ioconn = connectODBC connectionString
Prelude Database.HDBC Database.HDBC.ODBC> do { conn <- ioconn; vals <- quickQuery conn "SELECT TOP 10 * FROM mytable;" []; print vals }
[[SqlString "1",SqlString "Copy",...