https://wiki.haskell.org/api.php?action=feedcontributions&user=Dmboyd&feedformat=atomHaskellWiki - User contributions [en]2024-03-29T12:14:16ZUser contributionsMediaWiki 1.35.5https://wiki.haskell.org/index.php?title=HDBC-ODBC_under_Windows&diff=40422HDBC-ODBC under Windows2011-06-07T05:44:14Z<p>Dmboyd: /* Install */ add cabal</p>
<hr />
<div>[[Category:Libraries]] [[Category:How to]]<br />
A brief description of how to get HDBC-ODBC working under [[windows]], for connecting to things like MS SQL server.<br />
<br />
== Install ==<br />
<br />
* Ensure your path contains the [[GHC|ghc]] bin directory:<br />
** Right click on My Computer, select Properties -> Advanced -> Environment variables -> change the variable 'Path'<br />
* Download and install MDAC/ODBC Software Development Kit, from a link on this page:<br />http://msdn.microsoft.com/data/ref/mdac/downloads/<br />
* Download and unpack the most recent versions of hdbc and hdbc-odbc hackage.haskell.org<br />
* Follow the README instructions for installing [[HDBC | hdbc]]<br />
* Follow the README instructions for installing hdbc-odbc, with these changes:<br />
** The include-dirs line should be changed to:<br/>include-dirs: . "C:\\Program Files\\Microsoft Data Access SDK 2.8\\Libs\\x86"<br />
** Do the following at a command prompt, with the hdbc-odbc directory being current directory:<br/><br />
ghc --make -o setup Setup.hs<br />
setup configure<br />
setup build<br />
setup install<br />
<br />
Alternatively, as of the latest hackage build (HDBC-odbc-2.2.3.2) performing a cabal build works using:<br/><br />
cabal update<br />
cabal install HBC-odbc<br />
<br />
You may need other ODBC drivers, but often they will be installed already on a development box that has the database server installed.<br />
<br />
== Test ==<br />
You can test it from a [[GHC/GHCi| ghci]] prompt (obviously you'll need to change the connection string and query):<br />
<br />
<pre><br />
Prelude> :m Database.HDBC<br />
Prelude Database.HDBC> :m + Database.HDBC.ODBC<br />
Prelude Database.HDBC Database.HDBC.ODBC> let connectionString = "Driver={SQL Server};Server=myserver;Database=mydatabase;Trusted_Connection=yes;"<br />
Prelude Database.HDBC Database.HDBC.ODBC> let ioconn = connectODBC connectionString<br />
Prelude Database.HDBC Database.HDBC.ODBC> do { conn <- ioconn; vals <- quickQuery conn "SELECT TOP 10 * FROM mytable;" []; print vals }<br />
[[SqlString "1",SqlString "Copy",...<br />
</pre></div>Dmboyd