Connection String to MS SQL Server 2005

V

Vani Kulkarni

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
 
V

Vani Kulkarni

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



Felix said:
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")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top