rails-sqlserver / activerecord-sqlserver-adapter

SQL Server Adapter For Rails
MIT License
972 stars 559 forks source link

NoMemoryError Thrown with first access of Guid #52

Closed bairdrt closed 13 years ago

bairdrt commented 14 years ago

Awesome work on the adapter thus far guys! Amazing stuff.

I'm getting a ActiveRecord::StatementInvalid: NoMemoryError on my first access to a SqlServer GUID column. After the error is thrown, if I make the request immediately again, all is well. First time reporting an issue on github so I'm not sure what is generally supplied or proper etiquette.

Below is the stack trace thrown, please contact me for more information. I would love to help actually dig into the code and help resolve this - but I'll probably need a bit of guidance.

irb(main):002:0>  Territory.find_by_Name("Midwest").TerritoryId
ActiveRecord::StatementInvalid: NoMemoryError: failed to allocate memory: SELECT TOP 1 * FROM [Territory] WHERE ([Territory].[Name] = 'Midwest')
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract_adapter.rb:221:in `rescue in log'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract_adapter.rb:204:in `log'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter.rb:939:in `raw_select'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-2.3.8/lib/active_record/connection_adapters/sqlserver_adapter.rb:900:in `select'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all_with_query_cache'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/base.rb:664:in `find_by_sql'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/base.rb:1578:in `find_every'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/base.rb:1535:in `find_initial'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/base.rb:616:in `find'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/base.rb:1910:in `find_by_Name'
        from C:/Ruby191/lib/ruby/gems/1.9.1/gems/activerecord-2.3.8/lib/active_record/base.rb:1915:in `method_missing'
        from (irb):2
        from C:/Ruby191/bin/irb:12:in `<main>'
irb(main):003:0>  Territory.find_by_Name("Midwest").TerritoryId
=> "389AC126-48CE-DE11-8717-0050569A6D92"

I am running 1.9 on a windows machine, so there's lots of potential culprits here - but I thought this would be a good place to start.

metaskills commented 14 years ago

Agreed about lots of culprits on Windows :)

On a positive side, maybe look over the platform installation for Windows on the wiki articles. It does list some common pitfalls. I suspect this would be an error in your low level connection mode. Perhaps in the ODBC layer?

bairdrt commented 14 years ago

Thanks for the super fast response! I've checked wiki's, issue trackers and FAQs for similar issues, but to no avail. I know you're probably very busy, but if you're interested in helping me get up to speed with how to debug an issue like this I would love to try to troubleshoot and actually give back to project.

Is there anything I can/should do to dive a bit deeper into this?

metaskills commented 14 years ago

I'll try, not a fan of Windows nor am I any good at understanding the. You might want to send a link to the Google Group and start a discussion there. That way people with more Windows knowledge can help.

Till then, this would quantify the low level issue.

ActiveRecord::Base.connection.select_value "SELECT TOP 1 [TerritoryId] FROM [Territory] WHERE [Territory].[Name] = 'Midwest'" 

That's just a more direct way to see where the problem may be.

bairdrt commented 14 years ago

Interestingly enough - if I fire up irb, load in active record, establish my connection and then fire that off, no errors. I get the guid back just like I would expect.

... and now I'm completely confused as to what this would mean.

KDGundermann commented 14 years ago
bairdrt commented 14 years ago

I'm using ruby-odbc (0.99991), but I'm not sure how to tell if I'm utilizing utf or non-utf8 version. I'm certainly not doing anything to specify one over the other. Finally there are a few varchar/text fields in the table.

Please let me know if there is anything I can do to assist your investigation into this, I'd be more than happy to help in anyway.

KDGundermann commented 14 years ago

Please try the 0.99992 version of ruby-odbc

the old version has a problem with varchar/vartext fields.

metaskills commented 14 years ago

The 2-3-stable branch of the repo hold the upcoming 2.3.9 version of the adapter. If you are going to use the 0.99992 pre release ruby-odbc, then you should use the latest in that branch for the adapter. One 2.3.9 is released, use that.

bairdrt commented 14 years ago

FYI - I'm going to wait for 2.3.9 to be released prior to trying this upgrade. I'll report back once that's happened.

Thanks for your continued support!

metaskills commented 13 years ago

Gonna close this since it is ruby odbc specific and perhaps followed up under that project. TinyTds does handle guid's correctly.