Personal tools

HDBC-ODBC under Windows

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
 
m (Install)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
A brief description of how to get HDBC-ODBC working under windows, for connecting to things like MS SQL server.
+
[[Category:Libraries]] [[Category:How to]]
  +
A brief description of how to get HDBC-ODBC working under [[windows]], for connecting to things like MS SQL server.
   
= Install =
+
== Install ==
   
* Ensure your path contains the ghc bin directory:
+
* Ensure your path contains the [[GHC|ghc]] bin directory:
 
** Right click on My Computer, select Properties -> Advanced -> Environment variables -> change the variable 'Path'
 
** Right click on My Computer, select Properties -> Advanced -> Environment variables -> change the variable 'Path'
+
* Download and install MDAC/ODBC Software Development Kit, from a link on this page:<br />http://www.microsoft.com/en-us/download/details.aspx?id=5793
* Download and install MDAC/ODBC Software Development Kit, from a link on this page:<br />http://msdn.microsoft.com/data/ref/mdac/downloads/
+
* Download and unpack the most recent versions of hdbc and hdbc-odbc hackage.haskell.org
+
* Follow the README instructions for installing [[HDBC | hdbc]]
* Download and unpack the most recent versions of hdbc and hdbc-odbc from the HDBC homepage:<br />http://gopher.quux.org:70/devel/hdbc
 
 
* Follow the README instructions for installing hdbc
 
 
 
* Follow the README instructions for installing hdbc-odbc, with these changes:
 
* Follow the README instructions for installing hdbc-odbc, with these changes:
 
** The include-dirs line should be changed to:<br/>include-dirs: . "C:\\Program Files\\Microsoft Data Access SDK 2.8\\Libs\\x86"
 
** The include-dirs line should be changed to:<br/>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:<br/>
 
** Do the following at a command prompt, with the hdbc-odbc directory being current directory:<br/>
ghc --make -o setup Setup.hs
+
ghc --make -o setup Setup.hs
setup configure
+
setup configure
setup build
+
setup build
setup install
+
setup install
   
  +
Alternatively, as of the latest hackage build (HDBC-odbc-2.2.3.2) performing a cabal build works using:<br/>
  +
cabal update
  +
cabal install HDBC-odbc
   
 
You may need other ODBC drivers, but often they will be installed already on a development box that has the database server installed.
 
You may need other ODBC drivers, but often they will be installed already on a development box that has the database server installed.
   
= Test =
+
== Test ==
You can test it from a ghci prompt (obviously you'll need to change the connection string and query):
+
You can test it from a [[GHC/GHCi| ghci]] prompt (obviously you'll need to change the connection string and query):
   
 
<pre>
 
<pre>

Latest revision as of 10:06, 1 October 2013

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

[edit] 1 Install

  • Ensure your path contains the ghc bin directory:
    • Right click on My Computer, select Properties -> Advanced -> Environment variables -> change the variable 'Path'
  • Download and install MDAC/ODBC Software Development Kit, from a link on this page:
    http://www.microsoft.com/en-us/download/details.aspx?id=5793
  • Download and unpack the most recent versions of hdbc and hdbc-odbc hackage.haskell.org
  • 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

Alternatively, as of the latest hackage build (HDBC-odbc-2.2.3.2) performing a cabal build works using:

          cabal update
          cabal install HDBC-odbc

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

[edit] 2 Test

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",...