# MS SQL server connection problems

**URL:** <https://www.ruby-forum.com/t/ms-sql-server-connection-problems/51691>\
**Category:** Rails\
**Created:** [January 5, 2006, 11:45pm UTC](https://www.ruby-forum.com/t/ms-sql-server-connection-problems/51691 "2006-01-05T23:45:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@jeet](https://www.ruby-forum.com/u/jeet)\
**Post date:** [January 5, 2006, 11:45pm UTC](https://www.ruby-forum.com/t/ms-sql-server-connection-problems/51691/1 "2006-01-05T23:45:01Z")

</div>

I am trying to connect to a remote sql server and I am getting the  
following error:

c:/ruby/lib/ruby/site\_ruby/1.8/DBD/ADO/ADO.rb:57:in `connect': Open (DBI::Databa seError) OLE error code:80004005 in Microsoft OLE DB Provider for SQL Server [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. HRESULT error code:0x80020009 Exception occurred. from c:/ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:5 84:in `connect’

In my code I am creating a connection using the following code:

ActiveRecord::Base.establish\_connection(  
:adapter =\> “sqlserver”,  
:username =\> “TestUser”,  
:password =\> “TestUser”,  
:host =\> “[machine.domain.com](http://machine.domain.com)”,  
:database =\> “MY\_DB,1150”)

I can connect to the database from my machine using DBVisualizer, using  
the same parameters.

What could be the issue here?

–Navjeet

---

<div class="post-metadata">

**Author:** ![jeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@jeet](https://www.ruby-forum.com/u/jeet)\
**Post date:** [January 6, 2006, 12:22am UTC](https://www.ruby-forum.com/t/ms-sql-server-connection-problems/51691/2 "2006-01-06T00:22:18Z")

</div>

BTW, I was able to connect to the SQL Server by switching mode to ODBC  
and creating a DSN on my machine and specifying it in when creating a  
connection as below:

ActiveRecord::Base.establish\_connection(  
:adapter =\> “sqlserver”,  
:mode =\> “ODBC”,  
:dsn =\> “my\_dsn”,  
:username =\> “TestUser”,  
:password =\> “TestUser”,  
:host =\> “[machine.domain.com](http://machine.domain.com)”,  
:database =\> “MY\_DB,1150”)

Not knowing SQL Server too well, it may not supporting ADO access, not  
sure.

–Navjeet

Navjeet wrote:

> I am trying to connect to a remote sql server and I am getting the  
> following error:
> 
> c:/ruby/lib/ruby/site\_ruby/1.8/DBD/ADO/ADO.rb:57:in `connect': Open (DBI::Databa seError) OLE error code:80004005 in Microsoft OLE DB Provider for SQL Server [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. HRESULT error code:0x80020009 Exception occurred. from c:/ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:5 84:in `connect’
> 
> In my code I am creating a connection using the following code:
> 
> ActiveRecord::Base.establish\_connection(  
> :adapter =\> “sqlserver”,  
> :username =\> “TestUser”,  
> :password =\> “TestUser”,  
> :host =\> “[machine.domain.com](http://machine.domain.com)”,  
> :database =\> “MY\_DB,1150”)
> 
> I can connect to the database from my machine using DBVisualizer, using  
> the same parameters.
> 
> What could be the issue here?
> 
> –Navjeet

---

<div class="post-metadata">

**Author:** ![jeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@jeet](https://www.ruby-forum.com/u/jeet)\
**Post date:** [January 6, 2006, 2:43am UTC](https://www.ruby-forum.com/t/ms-sql-server-connection-problems/51691/3 "2006-01-06T02:43:11Z")

</div>

Gday,

> > denied.  
> > HRESULT error code:0x80020009  
> > Exception occurred. from  
> > c:/ruby/lib/ruby/site\_ruby/1.8/dbi/dbi.rb:5  
> > 84:in `connect’

Could it be that the remote SQL server currently only uses domain  
authentication, explaining why your machine can connect, but won’t  
accept password-only authentication? I believe this is the default  
behaviour. I had a similar issue with a PHP app.

- Andrew

---

<div class="post-metadata">

**Author:** ![jeet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ad7895/32.png) [@jeet](https://www.ruby-forum.com/u/jeet)\
**Post date:** [January 6, 2006, 4:04am UTC](https://www.ruby-forum.com/t/ms-sql-server-connection-problems/51691/4 "2006-01-06T04:04:15Z")

</div>

HI Navjeet,

Your first post appears to be using ADO Ok… you installed the ADO.rb  
from  
DBI right ?

First, try using :host =\> “(local)”  
Second, try using :host =\> “machine” instead of [machine.domain.com](http://machine.domain.com)  
Third, use SQL Query Analyzer or your other favorite SQL maintenance app  
to  
test your userid/pw. The userid/pw is the one that burns me most often,  
especially if you have newly created or restored your db.

## Any of those ideas work?

* * *

## Joyeux NoÃ«l

Peter F.
