我有一个带有Flask模板的Azure Web应用程序。我希望它连接到SQL数据库。我做了一个。我安装了pymssql。出于测试目的,我添加到根文件夹中的views.py:
import pymssql
conn = pymssql.connect(server='mydb.database.windows.net', user='mydbnameadmin@mydb', password='secret', database='mydb')
我首先在我的kubuntu盒子上进行本地测试。为了确保我获得连接,我输入了错误的密码,服务器抛出了错误。我输入正确,错误消失了。凉。此外,azure门户网站上的SQL仪表板报告了成功连接。然后我将我的更改(包括更新requirements.txt)推送到我的github仓库,它被吸入我的Web应用程序。当我尝试在索引页面上运行Web应用程序时:
由于内部服务器错误,页面无法显示 发生。
打开并检查详细日志后,我得到了它:
HTTP Error 500.0 - Internal Server Error
The page cannot be displayed because an internal server error has occurred.
Most likely causes:
IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
IIS was not able to process configuration for the Web site or application.
The authenticated user does not have permission to use this DLL.
The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.
IIS。这是做什么的?我认为MS很时髦,并在linux box 0_0
上托管这项服务我删除第二行
conn = pymssql.connect(server ='mydb.database.windows.net',user ='mydbnameadmin @ mydb',password ='secret',database ='mydb')
并且错误消失了。如果我在本地运行仍然使用Azure SQL服务器的服务器,我没有任何问题。
但是他们说他们是否真的使用了SQL数据库......
人们怎么想? 感谢
my requirements.txt
alembic==0.7.7
azure==0.11.1
Flask==0.10.1
Flask-Migrate==1.5.0
Flask-Script==2.0.5
Flask-SQLAlchemy==2.0
futures==3.0.3
itsdangerous==0.24
Jinja2==2.8
Mako==1.0.1
MarkupSafe==0.23
pymssql==2.1.1
python-dateutil==2.4.2
six==1.9.0
SQLAlchemy==1.0.8
Werkzeug==0.10.4
wheel==0.24.0
答案 0 :(得分:1)
根据我的理解,Azure网站默认托管在Windows Server 2012 VM上,不会安装FreeTDS
,我们也无权安装它。 pymssql
基于FreeTDS
。
因此,我们可以使用pyodbc
连接Azure SQL作为一种解决方法来轻松处理它。
答案 1 :(得分:1)
I was able to successfully connect my Python code to a SQL Database on Azure using the pymssql 2.1 library.
I don't know if this is what is causing the problem but I did include a couple of extra parameters in my connection string... maybe that will help. I specified the driver explicitly and the Encrypt parameter since SSL is always enabled for SQL Azure (I believe)
myConnection = pyodbc.connect('Driver={SQL Server};'
'Server=tcp:1234567.database.windows.net,1433;'
'Database=MyAzureDatabase;'
'Uid=geekgirl@123456;Pwd=abcdef;'
'Encrypt=yes')
If that doesn't work, maybe try adding some error handling around the connect statement to try and get a more specific error message.
Fingers crossed!
答案 2 :(得分:0)
我遇到了这个问题,但我最终意识到这是因为我在Visual Studio中使用的是64位版本的Python,但Azure只支持32位版本。
我看到了:
DLL load failed: %1 is not a valid Win32 application.
一旦我切换到安装和使用32位版本,我就可以毫无问题地使用Flask和pyodbc。