Connection String to MS SQL Server 2005

Hello all,

I have been to trying to connect to SQL Server 2005 from ruby code.
Following is the code written:

···

------------------------------------------------------------------------------
require 'dbi'

driver = 'ODBC'
server = "PRODSK0322"
database = 'TestDB'
user = 'sa'
password = 'Sa123'

connection_string = "DBI:ODBC:Driver={SQL
Server};Server=#{server};Database=#{database};Uid=#{user};Pwd=#{password}"

begin
  # connect
  db = DBI.connect(connection_string, user, password)
  # get data and print
  row = db.select_one("SELECT TrnEmployees")
  puts "result: " + row[0].to_s
rescue DBI::DatabaseError => e
  puts "Error #{e.errstr}"
ensure
  # disconnect from server
  db.disconnect if db
end

------------------------------------------------------------------------------

I am getting an error saying :
"Error IM002 (0) [Microsoft][ODBC Driver Manager] Data source name not
found and no default driver specified"

Can any one tell me where I am going wrong?
Is there anything I need to install or am I missing anything in includes
or requires?

Thanks,
Vani
--
Posted via http://www.ruby-forum.com/.

If you're attempting to connect via ODBC, you need to set up the ODBC source
separately.

On Linux, you would probably install FreeTDS and unixODBC, setting up
/etc/odbc.ini with an entry like this:

[My_SQL2005_Server]
Driver = FreeTDS
Description = SQL2005
Trace = No
Server = PRODSK0322
Port = 1433
Database = TestDB

On Windows, I'm not sure how to set up the ODBC sources.

Then you can connect with:

dbh = DBI.connect("DBI:ODBC:My_SQL2005_Server", "sa", "!Sa123")

···

-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Vani Kulkarni
Sent: Monday, July 30, 2007 5:11 AM
To: ruby-talk ML
Subject: Connection String to MS SQL Server 2005

Hello all,

I have been to trying to connect to SQL Server 2005 from ruby code.
Following is the code written:

--------------------------------------------------------------
----------------
require 'dbi'

driver = 'ODBC'
server = "PRODSK0322"
database = 'TestDB'
user = 'sa'
password = 'Sa123'

connection_string = "DBI:ODBC:Driver={SQL
Server};Server=#{server};Database=#{database};Uid=#{user};Pwd=
#{password}"

begin
  # connect
  db = DBI.connect(connection_string, user, password)
  # get data and print
  row = db.select_one("SELECT TrnEmployees")
  puts "result: " + row[0].to_s
rescue DBI::DatabaseError => e
  puts "Error #{e.errstr}"
ensure
  # disconnect from server
  db.disconnect if db
end

--------------------------------------------------------------
----------------

I am getting an error saying :
"Error IM002 (0) [Microsoft][ODBC Driver Manager] Data source
name not found and no default driver specified"

Can any one tell me where I am going wrong?
Is there anything I need to install or am I missing anything
in includes or requires?

Thanks,
Vani
--
Posted via http://www.ruby-forum.com/\.

Hello Felix,
I need to establish a connection to SQL Server 2005 on Windows.
Thanks,
Vani

Felix Windt wrote:

···

Following is the code written:

rescue DBI::DatabaseError => e
"Error IM002 (0) [Microsoft][ODBC Driver Manager] Data source

If you're attempting to connect via ODBC, you need to set up the ODBC
source
separately.

On Linux, you would probably install FreeTDS and unixODBC, setting up
/etc/odbc.ini with an entry like this:

[My_SQL2005_Server]
Driver = FreeTDS
Description = SQL2005
Trace = No
Server = PRODSK0322
Port = 1433
Database = TestDB

On Windows, I'm not sure how to set up the ODBC sources.

Then you can connect with:

dbh = DBI.connect("DBI:ODBC:My_SQL2005_Server", "sa", "!Sa123")

--
Posted via http://www.ruby-forum.com/\.

Try http://support.microsoft.com/kb/305599

That might help creating the DSN you refer to in "DBI:ODBC:DSN".

···

-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Vani Kulkarni
Sent: Monday, July 30, 2007 5:44 AM
To: ruby-talk ML
Subject: Re: Connection String to MS SQL Server 2005

Hello Felix,
I need to establish a connection to SQL Server 2005 on Windows.
Thanks,
Vani

Felix Windt wrote:
>> Following is the code written:
>>
>> rescue DBI::DatabaseError => e
>> "Error IM002 (0) [Microsoft][ODBC Driver Manager] Data source
>>
> If you're attempting to connect via ODBC, you need to set
up the ODBC
> source separately.
>
> On Linux, you would probably install FreeTDS and unixODBC,
setting up
> /etc/odbc.ini with an entry like this:
>
> [My_SQL2005_Server]
> Driver = FreeTDS
> Description = SQL2005
> Trace = No
> Server = PRODSK0322
> Port = 1433
> Database = TestDB
>
> On Windows, I'm not sure how to set up the ODBC sources.
>
> Then you can connect with:
>
> dbh = DBI.connect("DBI:ODBC:My_SQL2005_Server", "sa", "!Sa123")

--
Posted via http://www.ruby-forum.com/\.

Felix Windt wrote:

Vani
up the ODBC
> Server = PRODSK0322
Posted via http://www.ruby-forum.com/\.

Try http://support.microsoft.com/kb/305599

That might help creating the DSN you refer to in "DBI:ODBC:DSN".

Not sure whether this is acceptable for posting , but there is a site I
found which had a good snippet for connecting to SQL Server if you are
on a windows machine. It uses ADO and worked first go. there are also
other useful SQL Server snippets

http://snippets.dzone.com/posts/show/3906

···

--
Posted via http://www.ruby-forum.com/\.