Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Connection String to MS SQL Server 2005
Vani Kulkarni
7/30/2007 12:11:00 PM
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-...
.
2 Answers
Vani Kulkarni
7/30/2007 12:44:00 PM
0
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-...
.
Paul Tozer
8/3/2007 3:26:00 PM
0
Felix Windt wrote:
>> Vani
>> up the ODBC
>> > Server = PRODSK0322
>> Posted via
http://www.ruby-...
.
>>
>
> Try
http://support.microsoft.com...
>
> 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...
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Connection String to MS SQL Server 2005
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password