Hi Frank, You can look at the source code of `resultset-seq` (in Clojure-JVM) to see how it does a similar thing. You must consume the entire set of messages before closing the connection though. The `clojure.java.jdbc` library ensures that, for example.
You may also want to discuss this on ClojureCLR list: https://groups.google.com/forum/#!forum/clojure-clr Shantanu On Friday, 14 March 2014 13:44:27 UTC+5:30, Frank Behrens wrote: > > Hi, I wonder if its possible to convert this database query (its CLR) into > a lazy sequence. > > The reader loop is wrapped in the opening and closing of the db-connection > and reader. > > When i 'take a few records from the sequence, will then the connection be > closed > because it's getting out of scope and will be garbage collected ? > > How is it possible ? > > (defn user [conn-str] > (let [conn (System.Data.SqlClient.SqlConnection. conn-str) > _ (.Open conn) > cmd (System.Data.SqlClient.SqlCommand. > (str "SELECT name from User") conn) > reader (.ExecuteReader cmd)] > (let [out (loop [out '()] > (if (.Read reader) > (do > (print ".") > ((recur (conj out (.GetString reader 0))))) > out))] > (.Close reader) > (.Close conn) > out))) > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.