# Microsoft SQL Server has me stumped

**URL:** <https://www.ruby-forum.com/t/microsoft-sql-server-has-me-stumped/55902>\
**Category:** Rails\
**Created:** [March 24, 2006, 10:18pm UTC](https://www.ruby-forum.com/t/microsoft-sql-server-has-me-stumped/55902 "2006-03-24T22:18:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [March 24, 2006, 10:18pm UTC](https://www.ruby-forum.com/t/microsoft-sql-server-has-me-stumped/55902/1 "2006-03-24T22:18:16Z")

</div>

I’m tinkering around with an old legacy table in SQL Server 2000.  
Ruby 1.8.4, most recent ADO.rb file from RubyForge, Rails 1.0

Here’s the model:

class InventoryItem \< ActiveRecord::Base  
set\_table\_name “[_SMDBA_].[_INVENTOR_]”  
set\_primary\_key “sequence”  
end

Everything works fine. I can retrieve records without issue.

However, when create a new instance of InventoryItem, there are no  
attributes returned!

i = InventoryItem.new  
#\<InventoryItem:0x365eee0 @new\_record=true, @attributes={}\>

Anyone know where I would start looking?

Seems strange then that InventoryItem.find(:first) would return a full  
attribute set with all of the data appropriately assigned…

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [March 24, 2006, 11:16pm UTC](https://www.ruby-forum.com/t/microsoft-sql-server-has-me-stumped/55902/2 "2006-03-24T23:16:09Z")

</div>

Sorry, but what attributes are you expecting when creating brand new  
record  
using InventoryItem.new?

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [March 25, 2006, 5:45am UTC](https://www.ruby-forum.com/t/microsoft-sql-server-has-me-stumped/55902/3 "2006-03-25T05:45:52Z")

</div>

Well, generally, I’d have an attributes hash filled with the fields in  
my  
table.  
I have a column in the table called “computername”  
When I do

i = InventoryItem.new  
i.computername = ‘test’

I get a NoMethodException.

It’s really strange. It happens with all of my other tables as well.

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [March 25, 2006, 12:34pm UTC](https://www.ruby-forum.com/t/microsoft-sql-server-has-me-stumped/55902/4 "2006-03-25T12:34:56Z")

</div>

Have you tried making a copy of the table without the underscore  
characters and see if that works?

Just thinking that the underscores have meaning and may be clouding the  
logic.

Does the sequence field have meaing in rails?

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [March 25, 2006, 7:04pm UTC](https://www.ruby-forum.com/t/microsoft-sql-server-has-me-stumped/55902/5 "2006-03-25T19:04:06Z")

</div>

Ugh. If I have to remove the underscores then there’s no way I can use  
Rails  
for this project. These are legacy tables for a third-party (purchased)  
system.

As for updating, it appears to be working just fine.

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [March 27, 2006, 6:51pm UTC](https://www.ruby-forum.com/t/microsoft-sql-server-has-me-stumped/55902/6 "2006-03-27T18:51:29Z")

</div>

I found my own solution to this problem. The square brackets that wrap  
the  
table name had to be removed.

set\_table\_name “_SMDBA_._INVENTOR_”

instead of  
set\_table\_name “[_SMDBA_].[_INVENTOR_]”

Thanks for the suggestions.

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [March 25, 2006, 10:16am UTC](https://www.ruby-forum.com/t/microsoft-sql-server-has-me-stumped/55902/7 "2006-03-25T10:16:35Z")

</div>

Brian H. wrote:

> ```
> Anyone know where I would start looking?
> 
> ```

Can you update an existing InventoryItem?
