I am starting a project in Pylons that will need to access a MSSQL
database. I plan to develop on Windows and deploy on Linux. It sounds
like pyodbc is the best option and that it is reasonably well
supported. I've done a lot of Google searching but I haven't been able
to find answers to the following issues.
1. What is the correct format for the connection url?
My guess was the following:
engine = create_engine('mssql://username:password@hostname:port/database',
echo=True, module=pyodbc)
but engine.connect() fails.
Should the hostname be the IP of the server or SQL Server's
host\instance combination?
Isn't the port normally 1433?
2. I saw an archived email that said there was better support for
MSSQL in 0.3 than in 0.4. Is that still the case?
3. I'll be piggy backing on an existing ERP system and I'm trying to
decide what would be the best way to store new tables
- in the DB used by the ERP system
- in a new DB on the same MSSQL server
- in a SQLite DB
How easy does SA make it to use data from multiple DBs?
Thank you very much for your help and work on SQLAlchemy,
Scott
also check dbcook.usage.sa_engine_defs.py at
(svn co)
https://dbcook.svn.sourceforge.net/svnroot/dbcook/trunk/dbcook/usage/
for some create/drop stuff, both pyodbs/pymssql.
> 3. I'll be piggy backing on an existing ERP system and I'm trying
> to decide what would be the best way to store new tables
> - in the DB used by the ERP system
> - in a new DB on the same MSSQL server
> - in a SQLite DB
>
sqlite db will be cheapest and fastest (in the means of rapid
develpment), but might not support all magic u want, e.g. sequences
etc. i'll say go initialy for sqlite, dont rely on specific mssql
features, and timely try things on mssql to prevent surprises. Then
once u have 70+% there, specialize if need be.
> How easy does SA make it to use data from multiple DBs?
transparent enough for an antisqler like me.
see copyall.py at
https://dbcook.svn.sourceforge.net/svnroot/dbcook/trunk/dbcook/misc/metadata/
have fun
svil
Thank you svil for the link and helpful reply.
I'm afraid though that I still don't understand how to correctly setup
the connection. Slow learner I guess.
DatabaseNotes gives the following example:
db = create_engine('mssql://user:pass@db', module=pymssql)
but that doesn't help me much since it's not clear what goes in the place of db.
Am I supposed to create a system/file DSN under Windows with the ODBC
Data Source Administrator? If username and password are in the DSN do
they need to be in the url? Is hostname going to be host\instance?
Sorry if the answers to these questions are obvious.
Thanks,
Scott
mssql://user:password@server/database
Where server is the name or IP address of your SQL Server and database
is the name of the database on that server.
Hope that helps.
Cheers,
Gary.
i checked pyodbc on linux and mssql several weeks ago.
i succeeded to connect after i create a DSN and checked that the
connection worked with DataManager (comes from unixodbc-bin package on
Ubuntu). Another thing that you must check is on windows side to open
the port of mssql to pass trough firewall. If you cant connect with
DataManager try simple
~$ telnet ip_address_of_mssql_server port
command. when you are manage to connect by DataManager then check
sqlalchemy connection - i succeeded with:
import pyodbc
db_mssql = create_engine( 'mssql://username:password@name_of_the_DSN/?
use_scope_identity=1', module= pyodbc)
> I'm afraid though that I still don't understand how to correctly setup
> the connection. Slow learner I guess.
>
> DatabaseNotes gives the following example:
> db = create_engine('mssql://user:pass@db', module=pymssql)
>
> but that doesn't help me much since it's not clear what goes in the place of db.
>
> Am I supposed to create a system/file DSN under Windows with the ODBC
> Data Source Administrator? If username and password are in the DSN do
> they need to be in the url?
u and p must be in the url
hope this helps
regards,
stefan
>Should the hostname be the IP of the server or SQL Server's
>host\instance combination?
>
>
Both work ok for me.
>Isn't the port normally 1433?
>
>
Yup
>2. I saw an archived email that said there was better support for
>MSSQL in 0.3 than in 0.4. Is that still the case?
>
>
Support in 0.4 is pretty solid, main issue is update/delete statements
on tables that have a schema. That should get fixed pretty soon.
Paul