Welcome, guest | Sign In | My Account | Store | Cart

This simple code shows ODBC data sources. It uses odbc module.

Python, 24 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python
# -*- coding: utf8 -*-
__version__ = '$Id: odbc_sources.py 1696 2013-12-10 11:03:08Z mn $'

# shows ODBC data sources with driver info

# author: Michal Niklas

import odbc


def show_odbc_sources():
	sl = []
	source = odbc.SQLDataSources(odbc.SQL_FETCH_FIRST)
	while source:
		dsn, driver = source
		sl.append('%s [%s]' % (dsn, driver))
		source = odbc.SQLDataSources(odbc.SQL_FETCH_NEXT)
	sl.sort()
	print('\n'.join(sl))


if __name__ == '__main__':
	show_odbc_sources()

3 comments

Ben Rousch 10 years, 4 months ago  # | flag

Which ODBC module are you using? I don't see one in the standard library, and several are available at https://wiki.python.org/moin/ODBC

Michal Niklas (author) 10 years, 4 months ago  # | flag

odbc module is a part of ActiveState distribution (tested with 2.7 and 3.3). I believe it is also in PyWin32 package.