# Making ODBC connections without explicitly coding a password

**URL:** <https://www.ruby-forum.com/t/making-odbc-connections-without-explicitly-coding-a-password/118302>\
**Category:** Ruby\
**Created:** [October 25, 2007, 1:57pm UTC](https://www.ruby-forum.com/t/making-odbc-connections-without-explicitly-coding-a-password/118302 "2007-10-25T13:57:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anneb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8797f3/32.png) [@anneb](https://www.ruby-forum.com/u/anneb)\
**Post date:** [October 25, 2007, 1:57pm UTC](https://www.ruby-forum.com/t/making-odbc-connections-without-explicitly-coding-a-password/118302/1 "2007-10-25T13:57:31Z")

</div>

We’re developing Ruby programs which read and write from/to DB2 tables  
on a mainframe. We’re the first people in the company to use Ruby so  
are rather feeling our way. So far we’ve been using our own IDs and  
passwords, explicitly coded, to make ODBC connections to access  
development tables, but I’ve learnt that due to our security rules I  
won’t be allowed to know the password for the ID which will access live  
tables. Can anyone please suggest a way round explicitly coding the  
password? Thank you.

---

<div class="post-metadata">

**Author:** ![anneb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8797f3/32.png) [@anneb](https://www.ruby-forum.com/u/anneb)\
**Post date:** [October 25, 2007, 3:50pm UTC](https://www.ruby-forum.com/t/making-odbc-connections-without-explicitly-coding-a-password/118302/2 "2007-10-25T15:50:06Z")

</div>

On 10/25/07, Anne B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> We’re developing Ruby programs which read and write from/to DB2 tables  
> on a mainframe. We’re the first people in the company to use Ruby so  
> are rather feeling our way. So far we’ve been using our own IDs and  
> passwords, explicitly coded, to make ODBC connections to access  
> development tables, but I’ve learnt that due to our security rules I  
> won’t be allowed to know the password for the ID which will access live  
> tables. Can anyone please suggest a way round explicitly coding the  
> password? Thank you.

You can prompt for a password, but of course that doesn’t work for  
automated scripts.

If your DBAs know what they are doing, then security shouldn’t be a  
problem with live tables. I’m assuming that you will only be doing  
queries and not inserts/updates?

Todd

---

<div class="post-metadata">

**Author:** ![anneb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8797f3/32.png) [@anneb](https://www.ruby-forum.com/u/anneb)\
**Post date:** [October 25, 2007, 7:25pm UTC](https://www.ruby-forum.com/t/making-odbc-connections-without-explicitly-coding-a-password/118302/3 "2007-10-25T19:25:23Z")

</div>

Anne B. wrote:

> We’re developing Ruby programs which read and write from/to DB2 tables  
> on a mainframe. We’re the first people in the company to use Ruby so  
> are rather feeling our way. So far we’ve been using our own IDs and  
> passwords, explicitly coded, to make ODBC connections to access  
> development tables, but I’ve learnt that due to our security rules I  
> won’t be allowed to know the password for the ID which will access live  
> tables. Can anyone please suggest a way round explicitly coding the  
> password? Thank you.

If you are on Windows, you can set up a system DSN with the username and  
password encoded there. Using DBI, you can then just reference the DSN  
to access the database such as:

dbh = DBI.connect(“DBD:ODBC:myDSN”)

HTH,  
Jim

---

<div class="post-metadata">

**Author:** ![anneb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8797f3/32.png) [@anneb](https://www.ruby-forum.com/u/anneb)\
**Post date:** [December 21, 2007, 3:18pm UTC](https://www.ruby-forum.com/t/making-odbc-connections-without-explicitly-coding-a-password/118302/4 "2007-12-21T15:18:57Z")

</div>

Jim C. wrote:

> Anne B. wrote:
> 
> > We’re developing Ruby programs which read and write from/to DB2 tables  
> > on a mainframe. We’re the first people in the company to use Ruby so  
> > are rather feeling our way. So far we’ve been using our own IDs and  
> > passwords, explicitly coded, to make ODBC connections to access  
> > development tables, but I’ve learnt that due to our security rules I  
> > won’t be allowed to know the password for the ID which will access live  
> > tables. Can anyone please suggest a way round explicitly coding the  
> > password? Thank you.
> 
> If you are on Windows, you can set up a system DSN with the username and  
> password encoded there. Using DBI, you can then just reference the DSN  
> to access the database such as:
> 
> dbh = DBI.connect(“DBD:ODBC:myDSN”)
> 
> HTH,  
> Jim

Hi Jim

Belated but grateful thanks, this worked very nicely.

Anne
