使用pyodbc和机器学习服务打开连接到SQL Server DB的问题。

问题描述 投票:0回答:1

我在我们的一台服务器上安装了Anaconda,一些代码成功打开了与SQL(2016)的连接,在 另一个 的服务器。

import pyodbc

conn_string = 'DRIVER={SQL Server Native Client 11.0};SERVER=wpic-smir;Trusted_Connection=yes'
conn = pyodbc.connect(conn_string)
cursor=conn.cursor()

qstring = 'select UserID from Diler_BW.Beckwith.V_Thermovals'
cursor.execute(qstring)

row=cursor.fetchone()
print row[0]

del cursor
del conn

现在,在与Anaconda相同的服务器上,我们安装了SQL Server(2017),并且还安装了Python的机器学习服务。 我试图做运行基本上相同的代码,但从SQL内。

exec sp_execute_external_script
@LANGUAGE = N'Python',
@script = N'

import pyodbc

conn_string = ''DRIVER={SQL Server Native Client 11.0};SERVER=wpic-smir;Trusted_Connection=yes''
conn = pyodbc.connect(conn_string)
cursor=conn.cursor()

qstring = ''select UserID from Diler_BW.Beckwith.V_Thermovals''
cursor.execute(qstring)

row=cursor.fetchone()
print row[0]

del cursor
del conn
'

代码从独立的Anaconda中成功运行,但是,从连接到2017服务器的SQL查询中,它不能。

Msg 39004, Level 16, State 20, Line 0
A 'Python' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 2, Line 0
An external script error occurred: 

Error in execution.  Check the output for more information.
Traceback (most recent call last):
  File "<string>", line 5, in <module>
  File "C:\ProgramData\MSSQLSERVER\Temp-PY\Appcontainer1\41EF254D-1B14-4D9D-99AF-8AD356A84BDC\sqlindb_0.py", line 39, in transform
    conn = pyodbc.connect(conn_string)
pyodbc.OperationalError: ('08001', '[08001] [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [65].  (65) (SQLDriverConnect); [08001] [Microsoft][SQL Server Native Client 11.0]Login timeout expired (0); [08001] [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (65)')


Msg 39019, Level 16, State 2, Line 0
An external script error occurred: 
SqlSatelliteCall error: Error in execution.  Check the output for more information.
STDOUT message(s) from external script: 

Express Edition will continue to be enforced.
SqlSatelliteCall function failed. Please see the console output for more information.
Traceback (most recent call last):
  File "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\computecontext\RxInSqlServer.py", line 605, in rx_sql_satellite_call
    rx_native_call("SqlSatelliteCall", params)
  File "C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\RxSerializable.py", line 375, in rx_native_call
    ret = px_call(functionname, params)
RuntimeError: revoscalepy function failed.

我用于开发的账户在两台服务器上都是sysadmin角色。 我们在两台服务器上只使用Windows认证。 我猜测SQLMLS使用的python实例与单机安装有什么重大不同。

谢谢你。

python sql-server machine-learning pyodbc
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.