MSSQL Connection String (sqlalchemy.url)

1,730 views
Skip to first unread message

Victor Reichert

unread,
Jun 13, 2013, 6:58:30 PM6/13/13
to sqlalchem...@googlegroups.com

Hi,

I'm working through the Alembic tutorial and I have reached the point where I need to enter the DB URL (sqlalchemy.url).

The URL below (with the DSN py_test) works and I am able to run my migration, but I would like to connect without the DSN.

sqlalchemy.url =  mssql+pyodbc://py_test; Trusted_Connection=Yes

I am able to connect to the DB with SQL Alchemy using the URL in the line below:

sqlalchemy.url = mssql+pyodbc:///?odbc_connect=DRIVER={SQL Server};Server=Server;Database=DB;Trusted_Connection=Yes

However, it generates the following error.

sqlalchemy.exc.DBAPIError: (Error) ('08001', '[08001] [Microsoft][ODBC SQL Server Driver]Neither DSN nor SERVER keyword supplied (0) (SQLDriverConnect)') None None

I think the URL is ncoded in SQL Alchmey, and I have tried the line below as well:

sqlalchemy.url = mssql+pyodbc:///?odbc_connect=DRIVER%3D%7BSQL+Server%7D%3BServer%3DServer%3BDatabase%3DDB%3BTrusted_Connection%3DYes

Which generates the error below:

 "'%%' must be followed by '%%' or '(', found: %r" % (rest,)) ConfigParser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%3D%7BSQL+Server%7D%3BServer%3DServer%3BDatabase%3DDB%3BTrusted_Connection%3DYes;Trusted_Connection=Yes'

If anyone could please help me I would greatly appreciate it.

Thank you in advance :)

~Victor

Michael Bayer

unread,
Jun 13, 2013, 7:44:23 PM6/13/13
to sqlalchem...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alem...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Victor Reichert

unread,
Jun 13, 2013, 8:32:51 PM6/13/13
to sqlalchem...@googlegroups.com
Is there a way for me to see what connection string Alembic is using?  I would have expected the encoded url to haved worked.  Perhaps it is not calling what I think it is.
 
Thank you for responding so quickly!
 
~Victor
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alembic+unsub...@googlegroups.com.

Michael Bayer

unread,
Jun 13, 2013, 10:07:53 PM6/13/13
to sqlalchem...@googlegroups.com
funny I just gave this to someone last week.  use this script to experiment with URLs:

from sqlalchemy.connectors import pyodbc
from sqlalchemy.engine.url import make_url

conn = pyodbc.PyODBCConnector()
url = make_url('mssql+pyodbc://DSN=py_test; Trusted_Connection=Yes')
connect_args = conn.create_connect_args(url)
print(connect_args)




To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alem...@googlegroups.com.

Victor Reichert

unread,
Jun 14, 2013, 12:52:30 PM6/14/13
to sqlalchem...@googlegroups.com
Unfortunately, that was me.  I used the script you had given me to generate the tests.    I don't know why mssql+pyodbc:///?odbc_connect=DRIVER={SQL Server};Server=Server;Database=DB;Trusted_Connection=Yes doesn't work in Alembic as it does in SQL Alchmey.  However, after reading through the code I realized all I needed was mssql+pyodbc://@Server/DB.  Initially I thought I needed to specify Trusted_Connection=Yes (and I was jumping through some hoops to do do so), but it defaults to it if the user name is not supplied.
 
Thank you again for your help,
 
~Victor
Reply all
Reply to author
Forward
0 new messages