Unable to connect to mssql database

1,220 views
Skip to first unread message

Random

unread,
May 21, 2012, 2:48:34 PM5/21/12
to web...@googlegroups.com
Hello everyone,

It seems that I'm unable to connect to a mssql database.  I am getting the error:

Traceback (most recent call last):
  File "gluon/dal.py", line 5955, in __init__
  File "gluon/dal.py", line 2280, in __init__
RuntimeError: Unable to import driver

when using the connection string:

db = SQLDB('mssql://username:password@\\server\instance/databasename')

However I am able to connect using pymssql module in regular Python 2.7 using the connection string (with the same credentials):

pymssql.connect(host='hostname', user='username', password='password', database='database')

Any ideas?  Thanks in advance.

Andrew

unread,
May 21, 2012, 3:09:31 PM5/21/12
to web...@googlegroups.com
Have you installed pyodbc ? It's needed for mssql
http://www.web2py.com/books/default/chapter/29/6#Dependencies

Anthony

unread,
May 21, 2012, 3:45:52 PM5/21/12
to web...@googlegroups.com
Yes, web2py uses pyodbc for MSSQL as well as a few other databases: http://code.google.com/p/web2py/source/browse/gluon/dal.py#2529.

Random

unread,
May 21, 2012, 4:03:55 PM5/21/12
to web...@googlegroups.com
Yes I have installed pyodbc. However when I run this 

import pyodbc
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=SERVER;DATABASE=NAME;UID=USERNAME;PWD=PASSWORD')
cursor = cnxn.cursor()


I get a login failed.  My username is COMPANYDOMAINNAME\username to get access to the database.  The error message it's reporting back is that the user COMPANYDOMAINNAME\\username login failed.

It is automatically putting two forward slashes when my username only contains one. However it does not automatically put two on the server instance SERVER\instance.  Is there any way to force it to only put one forward slash?

Random

unread,
May 21, 2012, 4:08:59 PM5/21/12
to web...@googlegroups.com
I am also getting the same error when I try to setup a DB connection in Django.  It is automatically putting two forward slashes on my username.

Jonathan Lundell

unread,
May 21, 2012, 5:13:20 PM5/21/12
to web...@googlegroups.com
You're using backslashes. Try forward slashes. (The doubling itself is harmless though; just display.)

Derek

unread,
May 21, 2012, 6:50:04 PM5/21/12
to web...@googlegroups.com
I've always setup a sql server login specific to my app. The "active directory" integrated mode doesn't seem to sit too well with Web2Py and MSSQL. 

Jonathan Lundell

unread,
May 21, 2012, 7:47:25 PM5/21/12
to web...@googlegroups.com
On May 21, 2012, at 1:08 PM, Random wrote:
I am also getting the same error when I try to setup a DB connection in Django.  It is automatically putting two forward slashes on my username.

The web2py parser wants forward slashes ('/'), not backslashes.

db = SQLDB('mssql://username:password@/server/instance/databasename')

However, the error you're getting is earlier than that. The MSSQL adapter does this:

    driver = globals().get('pyodbc',None)

...and the implication of the error message is that an earlier import pyodbc failed.

Ross Peoples

unread,
May 22, 2012, 2:39:01 PM5/22/12
to web...@googlegroups.com
I have been using MSSQL from Linux for quite some time. I use FreeTDS for my driver. This is my connection string:

db = DAL('mssql://user:password@server/db_name?DRIVER={FreeTDS}')

If you need help setting up FreeTDS / unixODBC, let me know. I have some notes on how to set this up using a Ubuntu machine.

Cacpacific O

unread,
Nov 9, 2013, 4:40:39 PM11/9/13
to web...@googlegroups.com
Hi Ross,

This is my first time to connect web2py with mssql using pyodbc, Cloud you please advice me how to set it up. Currently I got error message ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)') when I try to connect by using this command => import pyodbc => pyodbc.connect('.....


Thank again



On Wednesday, May 23, 2012 1:39:01 AM UTC+7, Ross Peoples wrote:
I have been using MSSQL from Linux for quite some time. I use FreeTDS for my driver. This is my connection string:

db = DAL('mssql://user:password@server/db_name?DRIVER={FreeTDS}')

If you need help setting up FreeTDS / unixODBC, let me know. I have some notes on how to set this up using a Ubuntu machine.dd
Reply all
Reply to author
Forward
0 new messages