Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7791799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:00:03+00:00 2026-06-01T22:00:03+00:00

I use the ruby-gem sequel to read utf-8-encoded data from a MSSQL-Server table. The

  • 0

I use the ruby-gem sequel to read utf-8-encoded data from a MSSQL-Server table.
The fields of the table are defined as nvarchar, they look correct in the Microsoft Server Management Studio (Cyrillic is Cyrillic, Chinese looks chinese).

I connect my database with

  db = Sequel.connect(
    :adapter=>'ado', 
    :host     =>connectiondata[:server], 
    :database=>connectiondata[:dsn], 
    #Login via SSO
  )

  sel = db[:TEXTE].filter(:language=> 'EN') 
  sel.each{|data| 
    data.each{|key, val|
      puts "#{val.encoding}: #{val.inspect}"  #-> CP850: ....
      puts val.encode('utf-8')
    }
  }      

This works fine for English, German returns also a useable result:

CP850: "(2 St\x81ck) f\x81r
(2 Stück) für ...

But the result is converted to CP850, it is not the original UTF-8.

Cyrillic languages (I tested with Bulgarian) and Chinese produce only ‘?’
(reasonable, because CP850 doesn’t include Chinese and Bulgarian characters).

I also connected via a odbc-connection:

    db = Sequel.odbc(odbckey,
      :db_type => 'mssql',  #necessary
      #:encoding => 'utf-8',  #Only MySQL-Adapter
    ) 

The result is ASCII-8BIT, I have to convert the data with force_encoding to CP1252 (not CP850!).
But Cyrillic and Chinese is still not possible.

What I tried already:

  • The MySQL-adapter seems to have an encoding option, with MSSQL I detected no effect.
  • I did similar tests with sqlite and sequel and I had no problem with unicode.
  • I installed SQLNCLI10.dll and used it as provider. But I get a Invalid connection string attribute-error (same with sqlncli).

So my closing question: How can I read UTF-8 data in MS-SQL via ruby and sequel?

My environment:

Client:

  • Windows 7
  • Ruby 1.9.2
  • sequel-3.33.0

Database:

  • SQL Server 2005
  • Database has collation Latin1_General_CI_AS

After preparing my question I found a solution. I will post it as an answer.
But I still hope, there is a better way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:00:06+00:00Added an answer on June 1, 2026 at 10:00 pm

    If you can avoid it, you really don’t want to use the ado adapter (it’s OK for read-only workloads, but I wouldn’t recommend it for other workloads). I would try the tinytds adapter, as I believe that will handle encodings properly, and it defaults to UTF-8.

    Sequel itself does not do any transcoding, it leaves the handling of encodings to the lower level driver.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From my previous question about timezones , I decided to use the Ruby gem
is there some ruby code I can use to install a gem from a
I have been trying to use the ruby-git gem to make commits etc from
I use Ruby on Rails 2.3 and gem 'tiny_mce' Gem uses TinyMCE 3.4 Gem
background: trying to use the twitter gem for ruby-on-rails. in routes: map.resources :twitter_sessions map.finalize_twitter_sessions
I want to use acts-as-taggable-on gem for my rails app. (rails 3.0.10 and ruby
I have to type rvm use ruby-1.9.3 every time I login to my server.
I want to use Ruby/Mikel Mail gem to access pop3, but am stuck finding
I'm trying to work out how to use the icalendar ruby gem, found at:
I am working with the Shopsense Ruby Gem however I am unable to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.