gpt4 book ai didi

python - 从 SQL Server 导入数据源函数失败

转载 作者:太空宇宙 更新时间:2023-11-03 21:32:06 26 4
gpt4 key购买 nike

我正在使用 Win10 x64、SQL Server 2017 x64、JyputerNotebook 并使用主 RevoScalePy 库。

我可以建立到本地服务器的连接、创建数据库、查询表等。但是,当我定义一个返回图像字节流的函数并按如下方式调用该函数时:

from IPython import display
import matplotlib.pyplot as plt
from revoscalepy import RxInSqlServer, rx_exec

# create a remote compute context with connection to SQL Server
sql_compute_context = RxInSqlServer(connection_string=connection_string.format(new_db_name))

# use rx_exec to send the function execution to SQL Server
image = rx_exec(send_this_func_to_sql, compute_context=sql_compute_context)[0]

# only an image was returned to my jupyter client. All data remained secure and was manipulated in my db.
display.Image(data=image)

...我收到错误:

[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'NB-IT-JIRAK\SJ01'.

ODBC Error in SQLDisconnect

Could not open data source. ImportDataSource function failed. Please see the console output for more information.

我遵循本教程:https://blogs.msdn.microsoft.com/mlserver/2018/07/10/run-r-and-python-remotely-in-sql-server-from-jupyter-notebooks-or-any-ide/我尝试在控制面板/管理工具/数据源中的 MS Access 驱动程序旁边为 SQL Server ODBC 17 驱动程序创建一个新的 DNS。如有帮助,我们将不胜感激。

最佳答案

我认为您正在尝试从 SQL Server 导入数据,对吧。试试这个方法。

import pypyodbc 
cnxn = pypyodbc.connect("Driver={SQL Server Native Client 11.0};"
"Server=Server_Name;"
"Database=DB_Name;"
"Trusted_Connection=yes;")

#cursor = cnxn.cursor()
#cursor.execute("select * from Actions")
cursor = cnxn.cursor()
cursor.execute('SELECT * FROM Actions')

for row in cursor:
print('row = %r' % (row,))

这里有一些资源可供您在业余时间浏览。

http://pymssql.org/en/latest/pymssql_examples.html

http://blogs.msdn.com/b/cdndevs/archive/2015/03/11/python-and-data-sql-server-as-a-data-source-for-python-applications.aspx

关于python - 从 SQL Server 导入数据源函数失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53459874/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com