I have a case where I need to be able to connect to different databases on different servers. Therefore, it's useful for me to be able to specify a DSN upon creation of the connection object. This also help with the new multiple database support proposal for Django (http://code.djangoproject.com/wiki/MultipleDatabaseSupport).
This probably isn't the cleanest way to implement it, but I did make it work in my copy of base.py, attached here.
- base.py 10.2KB
Comment #1
Posted on Oct 21, 2008 by Swift KangarooAnother possible solution would be something similar to the patch presented on this ticket: http://code.djangoproject.com/ticket/6710
This may not work so well with pyodbc, however, since it only accepts the two arguments (despite DB API 2.0 recommendations)
Regardless, I feel that there should be some way to specify the DSN on instantiation. This will be especially important with the upcoming work on the multiple database feature: http://code.djangoproject.com/ticket/1142
Comment #2
Posted on Nov 19, 2008 by Swift KangarooOne thing I did change in this after posting was to transform 'DSN' to 'dsn' (lower case). This makes it more consistent with DB API 2.0. The change also made it possible for me to transparently use both this backend and the postgresql_psycopg2 backend after applying this patch: http://code.djangoproject.com/ticket/6710
Comment #3
Posted on Dec 30, 2008 by Helpful HippoIMHO it would be better tow ait for the Django crew to decide on the multi-DB API before implementing this in our backend, meanwhile it would be better to maintain this as a private patch.
Comment #4
Posted on Dec 31, 2008 by Swift KangarooIn followup to comment #1, something like the referenced ticket[1] may now be possible as of pyodbc 2.1.3. With this release, keyword arguments were added to connect(), as detailed in the ticket[2] (Ironic that it got the same ticket #) and the Module wiki page[3]. I don't know if this is even a consideration, but it is at least, as I said, a possibility now.
[1] http://code.djangoproject.com/ticket/6710 [2] http://code.google.com/p/pyodbc/issues/detail?id=18 [3] http://code.google.com/p/pyodbc/wiki/Module
Status: New
Labels:
Type-Defect
Priority-Low