pyramid mssql connection string

242 views
Skip to first unread message

Alen Cerovic

unread,
Oct 1, 2014, 10:09:59 AM10/1/14
to pylons-...@googlegroups.com
Hi,

new to pyramid, actually installed it yesterday :) What would be correct "sqlalchemy.url" in "development.ini" to connect to ms sql server

I tried :
sqlalchemy.url = mssql://username:password@ServerIP\ServerInstancce/DbName

but getting error:
    return __import__('pyodbc')
ImportError: No module named pyodbc

tried also:

sqlalchemy.url = mssql+pyodbc://DSN=py_test

py_test is DSN name on my Win7 machine but same error

Please help

Michael Merickel

unread,
Oct 1, 2014, 11:56:07 AM10/1/14
to Pylons
You will need to install the driver package and any other dependencies
required by the particular dialect you are using.

For example, for the pyodbc driver you will see the docs claim you
need to install pyodbc.

http://docs.sqlalchemy.org/en/rel_0_9/dialects/mssql.html#module-sqlalchemy.dialects.mssql.pyodbc
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pylons-discus...@googlegroups.com.
> To post to this group, send email to pylons-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/pylons-discuss.
> For more options, visit https://groups.google.com/d/optout.

Alen Cerovic

unread,
Oct 1, 2014, 12:45:57 PM10/1/14
to pylons-...@googlegroups.com
thnx, installed pyodbc, connection now works :-) but after initialize_MyApp_db which successfully created "models" table I still get error in browser "Pyramid is having a problem using your SQL database"

tried to install pymssql but got error : "unable to find vcvarsall.bat", will continue with pyodbc for now

is there tutorial for working with legacy database, I want to make crud for existing tables, how do I define/scaffold a model without issuing "create table" statements
noob, please help :-)

Petr Blahos

unread,
Oct 1, 2014, 2:04:42 PM10/1/14
to pylons-discuss
Hi, 

I have 32bit python 2.7, 32 bit windows, pyodbc 3.0.6, and sqlalchemy 0.8, and my connection string 
is something like:

mssql://username:password@hostname/dbname?driver=SQL Server Native Client 10.0;unicode_results=True

where driver=... is the same text I found in the ODBC data source administrator on the tab Drivers.

I didn't need any pymssql, as pyodbc uses odbc drivers. You need to find a binary package 
of pyodbc. I think I use the one from: https://code.google.com/p/pyodbc/downloads/list

--
Petr

--
____________________
Message has been deleted

Alen Cerovic

unread,
Oct 1, 2014, 4:08:37 PM10/1/14
to pylons-...@googlegroups.com
thnx pb, made it partially working, after initialize_MyApp_db which successfully created "models" table I still get error in browser "Pyramid is having a problem using your SQL database"

another question: how to define models for existing database tables and tell pyramid not to alter my existing tables

Petr Blahos

unread,
Oct 2, 2014, 3:04:34 AM10/2/14
to pylons-discuss
> thnx pb, made it partially working, after initialize_MyApp_db which successfully created "models" table I still
> get error in browser "Pyramid is having a problem using your SQL database"

Is there any exception show in your console where you run your pserve?

> another question: how to define models for existing database tables and tell pyramid not to alter my existing tables

Your tables are created or modified by the initialize_MyApp_db script,
so if you do not run
it, the tables are not touched (unless you have put the actual code
that modifies the tables
elsewhere too). Just use your connection string to point to the actual
database. Start with
defining a model for one table, and when you have it connected,
continue with the rest.

--
Petr

Alen Cerovic

unread,
Oct 2, 2014, 3:14:42 AM10/2/14
to pylons-...@googlegroups.com
if somebody is experiencing same errors in first steps with pyramid and ms sql server:
I found the reason for "Pyramid is having a problem using your SQL database"
SqlAlchemy tried to execute:

SELECT TOP 1 models.id AS models_id, models.name AS models_name, models.value AS models_value FROM models WHERE models.name = 'one'
and got error : "The data types text and varchar are incompatible in the equal to operator"

When I changed column "models.name" type from "text" to "nvarchar" it works


my second question for legacy tables is still open for help :-)

Reply all
Reply to author
Forward
0 new messages