# Interop with Sql Mgmt Objects (SMO) - the "IronRuby Way"

**URL:** <https://www.ruby-forum.com/t/interop-with-sql-mgmt-objects-smo-the-ironruby-way/178947>\
**Category:** IronRuby\
**Created:** [November 13, 2009, 11:05pm UTC](https://www.ruby-forum.com/t/interop-with-sql-mgmt-objects-smo-the-ironruby-way/178947 "2009-11-13T23:05:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Wilkins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@Mark\_Wilkins](https://www.ruby-forum.com/u/Mark_Wilkins)\
**Post date:** [November 13, 2009, 11:05pm UTC](https://www.ruby-forum.com/t/interop-with-sql-mgmt-objects-smo-the-ironruby-way/178947/1 "2009-11-13T23:05:19Z")

</div>

Thanks to casualjim in #ironruby, I figured out a way to do what I  
needed, but would be interested to see if there is a more appropriate  
solution:

I’m trying to use SMO to script objects from a SqlServer DB, using IR.  
In particular, I am calling  
Microsoft::SqlServer::Management::Smo::Scripter.Script, which expects  
an array of SmoObject’s (SmoObject[]).

So…what is the best way to create this array?

I ended up doing the following:  
@arsmo = System::Collections::Generic::List[SqlSmoObject].new  
@arsmo \<\< dev.tables[“tablename”] # where dev.tables is a  
Smo::TableCollection  
scripter.Script @arsmo.to\_array

As I said…this works fine. And…it also reminded me that  
@arsmo.to\_array is much different than @arsmo.to\_a. Just curious if  
there is a better way?

I’ve tried something as simple as::  
@arsmo = []  
@arsmo \<\< dev.tables[“tablename”]  
scripter.Script @arsmo

but I always get: “TypeError: can’t convert Array into  
Microsoft::SqlServer::Management::Smo::SqlSmoObject[]”

p.s. I know I can also do dev.tables[“tablename”].script, but I was  
trying to assemble a list of everything I wanted scripted, then make  
one call

Thanks

Mark
