Hi, I am trying to find a way to access database (SQL SERVER) using IronRuby. One option is to use C# and ADO.NET classes to access the database but was wondering if IronRuby has a build in support for dynamic SQL so I don''t have to deal with ADO.NET for database access. -- Posted via http://www.ruby-forum.com/.
Ivan Porto Carrero
2009-Jun-17 19:19 UTC
[Ironruby-core] Accessing Database Using IronRuby
You can use any OR/M in the .NET space to connect to databases.Writing queries will be somewhat challenging though :) Jimmy also wrote a sql server adapter for activerecord that comes with rails so you could also use the rails OR/M ActiveRecord http://github.com/jschementi/activerecord-mssql-adapter/tree/master So you could use a ruby OR/M --- Met vriendelijke groeten - Best regards - Salutations Ivan Porto Carrero Blog: http://flanders.co.nz Twitter: http://twitter.com/casualjim Author of IronRuby in Action (http://manning.com/carrero) On Wed, Jun 17, 2009 at 9:13 PM, Mohammad Azam <lists at ruby-forum.com> wrote:> Hi, > > I am trying to find a way to access database (SQL SERVER) using > IronRuby. One option is to use C# and ADO.NET classes to access the > database but was wondering if IronRuby has a build in support for > dynamic SQL so I don''t have to deal with ADO.NET for database access. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090617/8e4c9184/attachment.html>
You could use the ActiveRecord SQLServer adapter ... Look for documentation under the Rails section in ironruby.net/documentation. ~Jimmy Sent from my phone On Jun 17, 2009, at 12:13 PM, "Mohammad Azam" <lists at ruby-forum.com> wrote:> Hi, > > I am trying to find a way to access database (SQL SERVER) using > IronRuby. One option is to use C# and ADO.NET classes to access the > database but was wondering if IronRuby has a build in support for > dynamic SQL so I don''t have to deal with ADO.NET for database access. > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >
Thanks! yeah I might be interested in using any .NET ORM! I will try out Jimmy Rails ORM ActiveRecord. I think it will also work for a windows application. Let me check out the dbi module. Ivan Porto carrero wrote:> You can use any OR/M in the .NET space to connect to databases.Writing > queries will be somewhat challenging though :) > > Jimmy also wrote a sql server adapter for activerecord that comes with > rails > so you could also use the rails OR/M ActiveRecord > > http://github.com/jschementi/activerecord-mssql-adapter/tree/master > > So you could use a ruby OR/M > > --- > Met vriendelijke groeten - Best regards - Salutations > Ivan Porto Carrero > Blog: http://flanders.co.nz > Twitter: http://twitter.com/casualjim > Author of IronRuby in Action (http://manning.com/carrero)-- Posted via http://www.ruby-forum.com/.
Hi Jimmy, Can I use the ActiveRecord SQL SERVER with Window Forms projects? -- Posted via http://www.ruby-forum.com/.
Just wanted to share basic code to insert first_name and last_name into the database. require ''mscorlib'' require ''System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'' SqlConnection = System::Data::SqlClient::SqlConnection SqlCommand = System::Data::SqlClient::SqlCommand class CustomerRepository def save(customer) connection = SqlConnection.new(''Server=localhost;Database=TestDatabase;Trusted_Connection=true'') connection.Open() command = SqlCommand.new("insert into customers(first_name,last_name) values(@first_name, at last_name)",connection) command.Parameters.AddWithValue("@first_name",customer.first_name) command.Parameters.AddWithValue("@last_name",customer.last_name) command.ExecuteNonQuery() connection.Close() end end -- Posted via http://www.ruby-forum.com/.
Thanks! I''ve added this to the IronRuby .NET documentation just as a placeholder: http://ironruby.net/Documentation/.NET/SQL ~js> -----Original Message----- > From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core- > bounces at rubyforge.org] On Behalf Of Mohammad Azam > Sent: Wednesday, June 17, 2009 1:33 PM > To: ironruby-core at rubyforge.org > Subject: Re: [Ironruby-core] Accessing Database Using IronRuby > > Just wanted to share basic code to insert first_name and last_name into the > database. > > > require ''mscorlib'' > require ''System.Data, Version=2.0.0.0, Culture=neutral, > PublicKeyToken=b77a5c561934e089'' > > SqlConnection = System::Data::SqlClient::SqlConnection > SqlCommand = System::Data::SqlClient::SqlCommand > > class CustomerRepository > > def save(customer) > > connection > SqlConnection.new(''Server=localhost;Database=TestDatabase;Trusted_Con > nection=true'') > connection.Open() > command = SqlCommand.new("insert into > customers(first_name,last_name) > values(@first_name, at last_name)",connection) > > command.Parameters.AddWithValue("@first_name",customer.first_name) > command.Parameters.AddWithValue("@last_name",customer.last_name) > > command.ExecuteNonQuery() > connection.Close() > > end > > end > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core
Definitely, WinForms isn''t anything special to restrict using SQLServer. I actually show this briefly here: http://blog.jimmy.schementi.com/2009/05/ironruby-at-railsconf-2009.html#sql Source code is here: http://github.com/jschementi/railsconf09/tree/master/8-ardb ~js> -----Original Message----- > From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core- > bounces at rubyforge.org] On Behalf Of Mohammad Azam > Sent: Wednesday, June 17, 2009 12:33 PM > To: ironruby-core at rubyforge.org > Subject: Re: [Ironruby-core] Accessing Database Using IronRuby > > Hi Jimmy, > > Can I use the ActiveRecord SQL SERVER with Window Forms projects? > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core