# Unable to connect to ms sql server

**URL:** <https://www.ruby-forum.com/t/unable-to-connect-to-ms-sql-server/62360>\
**Category:** Rails\
**Created:** [June 3, 2006, 7:45am UTC](https://www.ruby-forum.com/t/unable-to-connect-to-ms-sql-server/62360 "2006-06-03T07:45:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![avinash](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@avinash](https://www.ruby-forum.com/u/avinash)\
**Post date:** [June 3, 2006, 7:45am UTC](https://www.ruby-forum.com/t/unable-to-connect-to-ms-sql-server/62360/1 "2006-06-03T07:45:56Z")

</div>

I get the following error message when trying to connect to ms sql  
server:

Open  
OLE error code:80040E4D in Microsoft OLE DB Provider for SQL Server  
Login failed for user ‘XXXXXXXX’.  
HRESULT error code:0x80020009  
Exception occurred.

I google’d for those error codes but nothing useful so far. To set up  
ruby for ms sql server, I followed the instructions here:

[http://wiki.rubyonrails.com/rails/pages/HowtoConnectToMicrosoftSQLServer](http://wiki.rubyonrails.com/rails/pages/HowtoConnectToMicrosoftSQLServer)

I followed the first 2 steps (copying ado.rb and modifying  
database.yml) but I cannot get it to connect to the sql server.

Ofcourse, I have verified that the credentials are good since I am able  
to connect to the server from other interfaces.

Also, is there a way to force ruby to use windows authentication for  
connecting to sql servers?

## Any tips, thoughts? thanks in advance,

avinash

---

<div class="post-metadata">

**Author:** ![avinash](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@avinash](https://www.ruby-forum.com/u/avinash)\
**Post date:** [June 4, 2006, 8:57am UTC](https://www.ruby-forum.com/t/unable-to-connect-to-ms-sql-server/62360/2 "2006-06-04T08:57:34Z")

</div>

Hi Avinash,

Can you please tell me, what you see when you run the following script  
(assuming SQL Server 2K on Win XP):

#----------------------------------  
require ‘active\_record’

ActiveRecord::Base.establish\_connection(  
:adapter =\> “sqlserver”,  
:host =\> “DBI:ADO:Provider=SQLOLEDB;Data Source=(local);Initial  
Catalog=master;Integrated Security=SSPI”,  
:database =\> “master”  
)

class Sysobject \< ActiveRecord::Base  
end

tables = Sysobject.find\_by\_sql("select name from sysobjects where  
xtype = ‘U’ ")  
tables.each{|t| puts t.name}  
#--------------------------------------

I get to see all the names of user defined tables on my setup.

Once we get past this point on your setup, making it work in Rails is  
left as an exercise 🙂

HTH,

– Shashank

Avinash [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
I get the following error message when trying to connect to ms sql  
server:

* * *

Do You Yahoo!?  
Tired of spam? Yahoo! Mail has the best spam protection around

> **[\[object](https://mail.yahoo.com/)**
>
> \[object
