我已经设置了从边缘的Sql模块,这是存储从演示"tempsensor“模块的数据到码头容器基于sql数据库。数据可以通过Mssql-tools-sqlcmd访问,我可以在其中获取查询数据库。但是,当我尝试使用其他应用程序(我曾尝试使用python)访问数据库时,它对我不起作用
我已经尝试了pyodbc,但它不工作!当我尝试安装ODBC驱动程序时,我得到了一些超时错误。然后我尝试了FreeTDS驱动,这对我来说也不起作用。
链接- https://docs.microsoft.com/en-us/azure/iot-edge/tutorial-store-data-sql-server
#this shows I am getting the data from the table with sql tool
acn-iot2@acniot2-UPC-GWS01:~$ sudo docker exec -it sql bashroot@2b08418b1986:/# /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Strong!Passw0rd‘1> SELECT * FROM MeasurementsDB.dbo.TemperatureMeasurements 2> go measurementTime location temperature
-------------------------------------- -------------------------------------------------- ------------------------ 2019-06-10 11:36:46.9392878 machine 21.363193834486001 2019-06-10 11:36:46.9392878 ambient 20.628800209671599 2019-06-10 11:36:52.8738186 machine#############################################################################我使用的python代码
import pyodbc
server = 'localhost,1433'
database = 'MeasurementsDB'
username = 'su'
password = 'Strong!Passw0rd'
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL
Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+
password)
cursor = cnxn.cursor()我得到的错误如下
pyodbc.OperationalError: ('HYT00', '[HYT00] [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')但是当我尝试使用python阅读时,我无法阅读。
发布于 2019-06-12 14:23:18
虽然您的代码在应该是username = 'sa'的地方使用了username = 'su',但我猜这不是问题所在,因为您得到了超时。
我猜你是用运行在容器外部的python代码连接容器内部的数据库。
在这种情况下,您应该将python代码复制到容器中并运行,或者公开端口1433并连接到<container_id>:1433而不是localhost,1433
https://stackoverflow.com/questions/56545255
复制相似问题