# How do I do this in ruby?

**URL:** <https://www.ruby-forum.com/t/how-do-i-do-this-in-ruby/50631>\
**Category:** Ruby\
**Created:** [December 19, 2005, 11:43am UTC](https://www.ruby-forum.com/t/how-do-i-do-this-in-ruby/50631 "2005-12-19T11:43:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 19, 2005, 11:43am UTC](https://www.ruby-forum.com/t/how-do-i-do-this-in-ruby/50631/1 "2005-12-19T11:43:53Z")

</div>

Hi,

I am trying to write a script that downloads my web server statistics  
that is stored in an online MS SQL Database to a local database for  
further processing and then deletes the downloaded records (to save  
space online). How do I do this safely so that I don’t lose any records  
due to network error - is there some kind of a distibuted transaction  
coordinator that I can use in ruby?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 19, 2005, 11:58am UTC](https://www.ruby-forum.com/t/how-do-i-do-this-in-ruby/50631/2 "2005-12-19T11:58:58Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Hi,
> 
> I am trying to write a script that downloads my web server statistics  
> that is stored in an online MS SQL Database to a local database for  
> further processing and then deletes the downloaded records (to save  
> space online). How do I do this safely so that I don’t lose any  
> records due to network error - is there some kind of a distibuted  
> transaction coordinator that I can use in ruby?

That question is probably better answered in a SQL Server related news  
group. This sounds like a typical application of replication / staging.  
SQL Server does provide mechanisms for that. I’m sure you can even set  
a  
trigger that deletes records after successful replication. TX  
coordination can also be done with SQL Server. I can’t help with the  
details but I’m sure you’ll find info in BOL (SQL Server Books Online).

Kind regards

```
robert
```

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 19, 2005, 12:44pm UTC](https://www.ruby-forum.com/t/how-do-i-do-this-in-ruby/50631/3 "2005-12-19T12:44:12Z")

</div>

removed\_email\_address@domain.invalid wrote:

> 

actually, the methodology really depends on whether you are using the  
Windows version of Ruby or the \*nix version …

One option that will work either way is to build a simple DTS script  
that MSSQL should run on a routine basis to export listings to a file (  
CSV or XML ) …

Then you can access that via any means you have to access the filesystem  
… ( could be a samba mount of the filesystem, or ssh, or ftp, or  
whatever … ) then your script can parse the given file and dump into  
the database … of course if you’re following that methodology,  
there’s really nothing that keeps you from building a DTS script that  
would dump the data directly into a remote database ( anything you can  
access via an ODBC driver ).

… Anyways, the other option would be to use Ruby under windows with  
the compiled in ODBC drivers … then access the MSSQL database and do  
whatever you want … This option is possible from \*nix, but it’s a bit  
wierd since you need to access the MSSQL database using Sybase drivers (  
since that’s all MSSQL really uses for it’s protocol, just a heavily  
modified version of the Sybase protocol since MSSQL started life as just  
a modified version of the Sybase server… )

Hope those options help you.

Me, I’d just write a DTS to do whatever you want … you can schedule it  
within MSSQL and then not have to worry about it. And it keeps you from  
having to play in M$ land _too_ much 😉

j.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 20, 2005, 9:23am UTC](https://www.ruby-forum.com/t/how-do-i-do-this-in-ruby/50631/4 "2005-12-20T09:23:38Z")

</div>

Thanks guys. This was a great help. Guess I will try using DTS - it was  
an option I had ignored.

Kishor.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 19, 2005, 2:35pm UTC](https://www.ruby-forum.com/t/how-do-i-do-this-in-ruby/50631/5 "2005-12-19T14:35:27Z")

</div>

On Dec 19, 2005, at 6:43 AM, Jeff W. wrote:

> … Anyways, the other option would be to use Ruby under windows  
> with the compiled in ODBC drivers … then access the MSSQL  
> database and do whatever you want … This option is possible from  
> \*nix, but it’s a bit wierd since you need to access the MSSQL  
> database using Sybase drivers ( since that’s all MSSQL really uses  
> for it’s protocol, just a heavily modified version of the Sybase  
> protocol since MSSQL started life as just a modified version of the  
> Sybase server… )

My team has just begun writing a few data manipulation scripts in  
Ruby using ActiveRecord. We use it in ADO mode. To do so, we

- installed Ruby using the one-click Windows installer (http://  
[rubyinstaller.rubyforge.org/wiki/wiki.pl](http://rubyinstaller.rubyforge.org/wiki/wiki.pl))
- updated RubyGems ( c:\> gem update --system )
- installed ActiveRecord ( c:\> gem install activerecord )
- followed the directions here ([Peak Obsession](http://wiki.rubyonrails.com/rails/)  
pages/HowtoConnectToMicrosoftSQLServer) to set up ADO

The great thing about it is that we can issue raw SQL when needed,  
and we can use the ORM features of ActiveRecord when it’s beneficial  
to do so.

Good luck,  
Craig
