2

I am trying to create a cloudfaundry app on bluemix. It uses linux by default as a server. i am getting below error while i am tring to connect sql server db on azure

error:

pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'SQL 
Server' : file not found (0) (SQLDriverConnect)")

The code for connecting to db is here . I am using flask

@app.route('/sql/<lat>/<long>') 
def api_sql(lat,long):
 cnxn =pyodbc.connect('DRIVER{SQLServer};SERVER=prashantvikramsingh.database.windows.net;DATABASE=Zillow;UID=UserId;PWD=pass')
cursor = cnxn.cursor()

There is similar question here. How to do this step while deploying the app on bluemix. This step can be done in local machine. But how to do it on cloud? . Is there any way to fix this error

thse are the contents of envirnment.yml file in local

name: pyodbc-test
dependencies:
 - pyodbc
 - flask
 - itsdangerous
 - Jinja2
 - MarkupSafe
 - Werkzeug
 - unixODBC
4
  • I've tried a few options, but haven't been able to make any progress with this. Microsoft are now a member of the cloud foundry foundation, so maybe reach out to them asking for help. Commented Jul 12, 2017 at 9:36
  • It's missing the SQL Server driver and I'm not sure there's going to be an easy way to install that. The link you included requires sudo/root access and that's not possible on CF. You would need a way to install w/out root. Another possibility would be to make a package you can install with Conda, but the SQL Server driver is proprietary so I don't think you could legally do that (I'm not a lawyer though). If you're willing to use FreeTDS, that maybe a possible solution. Another might be using pymssql instead of ODBC. Commented Jul 12, 2017 at 11:57
  • @ChrisSnow will try that . thanks for all the help Commented Jul 12, 2017 at 13:49
  • @DanielMikusa . Thank you. Will try with pymssql and post the updates if there is success. Commented Jul 12, 2017 at 13:50

1 Answer 1

0

The SQL Server driver is for Windows only.

You'll want to look into installing and using either the FOSS FreeTDS or the Microsoft ODBC Driver for Linux 13.1:

http://www.freetds.org/userguide/install.htm https://blogs.technet.microsoft.com/dataplatforminsider/2017/02/08/odbc-driver-13-1-for-linux-released/

Then, in your connection string, if you're using FreeTDS, for example:

cnxn =pyodbc.connect('DRIVER={FreeTDS};SERVER=prashantvikramsingh.database.windows.net;DATABASE=Zillow;UID=UserId;PWD=pass;TDS_Version=7.2')

cursor = cnxn.cursor()

I've used FreeTDS for years and it has treated me well. Good luck!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.