<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc=" http://purl.org/dc/elements/1.1/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>briancarper.net (λ) (Tag: SQL Server)</title><link>http://briancarper.net/tag/105/sql-server</link><description>Some guy's blog about programming and Linux and cows.</description><item><title>Clojure, SLIME, ODBC, SQL Server</title><link>http://briancarper.net/blog/clojure-slime-odbc-sql-server</link><guid>http://briancarper.net/blog/clojure-slime-odbc-sql-server</guid><pubDate>Fri, 26 Jun 2009 11:27:22 -0700</pubDate><description>&lt;p&gt;I had a lot of trouble connecting to an MS SQL Server at work via Clojure.  Java 6 comes with a JDBC-ODBC bridge which worked fine from a Clojure REPL at a command prompt, or from inferior-lisp in Emacs, but in SLIME it would hang every time I tried to connect and I'd have to kill Java.  Couldn't for the life of me figure out why.&lt;/p&gt;

&lt;p&gt;I got it to work eventually by using Microsoft's own JDBC driver, which you can download &lt;a href=&quot;http://msdn.microsoft.com/en-us/data/aa937724.aspx&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you put the downloaded .jar file on your &lt;code&gt;CLASSPATH&lt;/code&gt; (in my case, &lt;code&gt;sqljdbc4.jar&lt;/code&gt;) you can connect like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;user&amp;gt; (def db {:classname &quot;com.microsoft.sqlserver.jdbc.SQLServerDriver&quot;
               :subprotocol &quot;sqlserver&quot;
               :subname &quot;//server_hostname;database=SomeDatabase;user=SomeUser;password=SomePassword&quot;})
#'user/db
user&amp;gt; (use 'clojure.contrib.sql)
nil
user&amp;gt; (with-connection db 
        (with-query-results rs [&quot;SELECT * FROM whatever&quot;] (prn rs)))
... results ...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Posted for the sake of Googlebot and for my own future sanity.&lt;/p&gt;</description></item></channel></rss>

