# MSSQL DB connection, multiplatform, NextRecordSet

**URL:** <https://www.ruby-forum.com/t/mssql-db-connection-multiplatform-nextrecordset/160914>\
**Category:** Ruby\
**Created:** [February 20, 2009, 9:30pm UTC](https://www.ruby-forum.com/t/mssql-db-connection-multiplatform-nextrecordset/160914 "2009-02-20T21:30:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![makkura](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@makkura](https://www.ruby-forum.com/u/makkura)\
**Post date:** [February 20, 2009, 9:30pm UTC](https://www.ruby-forum.com/t/mssql-db-connection-multiplatform-nextrecordset/160914/1 "2009-02-20T21:30:44Z")

</div>

I’m trying to find a way to use ruby to connect to a MS SQL database.

I need it to be as simple I can to run on both windows and linux  
systems. So if they require different things to make them work, I want  
to have the smallest difference in code that I can.

I also need to support stored procedures returning multiple record sets  
so something like .NextRecordSet needs to be supported.

I can get a connection using: require ‘dbi’ and ODBC BUT ODBC doesn’t  
appear to support multiple record sets.  
I’ve been attempting to get ADO to fall in line but, my understanding,  
is that it’s not very happy with linux.

So in summary:  
-MSSQL DB connection  
-Must be usable across Linux and Windows with minimal changes  
-Must allow for multiple record sets

Does anyone have suggestions for me?

Thanks in advance.  
~Makkur

---

<div class="post-metadata">

**Author:** ![makkura](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@makkura](https://www.ruby-forum.com/u/makkura)\
**Post date:** [February 22, 2009, 10:18am UTC](https://www.ruby-forum.com/t/mssql-db-connection-multiplatform-nextrecordset/160914/2 "2009-02-22T10:18:31Z")

</div>

2009/2/21 Joseph S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> So in summary:  
> -MSSQL DB connection  
> -Must be usable across Linux and Windows with minimal changes  
> -Must allow for multiple record sets

Hi, If it’s ok to use JRuby, you can try JDBC with JRuby. I have no  
experience in MSSQL and ADO, but i’m sure MSSQL provides JDBC driver  
and JDBC is inherently compatible across different platforms. And if I  
understood your point correctly, it supports multiple record sets as  
well. The following JRuby code works with my PostgreSQL database.

stmt.execute ‘select \* from test\_a; select \* from test\_b’  
rset = stmt.get\_result\_set  
while rset.next  
puts rset.get\_long(1)  
end

stmt.get\_more\_results  
rset = stmt.get\_result\_set  
while rset.next  
puts rset.get\_long(1)  
end

---

<div class="post-metadata">

**Author:** ![makkura](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/76d3ee/32.png) [@makkura](https://www.ruby-forum.com/u/makkura)\
**Post date:** [February 23, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/mssql-db-connection-multiplatform-nextrecordset/160914/3 "2009-02-23T15:25:26Z")

</div>

> Hi, If it’s ok to use JRuby, you can try JDBC with JRuby. I have no  
> experience in MSSQL and ADO, but i’m sure MSSQL provides JDBC driver  
> and JDBC is inherently compatible across different platforms. And if I  
> understood your point correctly, it supports multiple record sets as  
> well. The following JRuby code works with my PostgreSQL database.
> 
> stmt.execute ‘select \* from test\_a; select \* from test\_b’  
> rset = stmt.get\_result\_set  
> while rset.next  
> puts rset.get\_long(1)  
> end
> 
> stmt.get\_more\_results  
> rset = stmt.get\_result\_set  
> while rset.next  
> puts rset.get\_long(1)  
> end

I’m not familiar with JRuby.  
I’m fairly open to options so I’ll take a look at it.  
Just that it supports multiple record sets is a step forward.

Thanks for the heads up.
