开发者

Django-pyodbc SQL Server/freetds server connection problems on linux

Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnectW)')

I'm migrating from developing on a windows development machine to Linux machine in production and I'm having issues with the freetds driver. As far as I can tell that error message means it can't find the driver. I can connect via the cli via sqsh and tsql. I've setup my settings.py as such.

   'bc2db': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'DataTEST',
        'USER': 'appuser',
        'PASSWORD': 'PASS',
        'HOST': 'bc2.domain.com',
        'options': {
            'driver': 'FreeTDS',
            }
    },

Does anyone have any SQL Server experienc开发者_JAVA技巧e with django? do I have to use a dns? (how would I format that?)


I needed to use one of the supported configurations as supported by the freetds driver. I ended up putting the host information in the odbc.ini. The linked documentation has good examples over a few pages.


Here's an example of a database connection for SQL Server and django in case someone needs it, this is how it will look in the settings.py.

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'YourDBname',
        'USER': 'YourUsername',    
        'PASSWORD': '',
        'HOST': '',
        'OPTIONS' : {
            'driver': 'SQL Native Client',
            'dsn': 'YourDSNname',
            'MARS_Connection': True,
        },
    },    
}

Further information here...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜