在sql s上运行python(.py脚本)

2024-10-01 15:39:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直试图从SSIS运行python。所以我需要在sqlserver中创建一个包。我可以在sql server中运行小脚本,但不确定如何运行脚本。在

下面的工作。但我的python代码正在测试中_数据库如何在sqlserver中运行python脚本?在

EXEC sp_execute_external_script @language = N'Python', 
@script = N'print(3+4)'

来自外部脚本的标准输出消息:

7


Tags: 代码脚本数据库executesql标准serverscript
2条回答

从SSIS执行python脚本有两种方法:

(1) 使用执行进程任务执行Python脚本

可以使用从Execute Process Task执行python脚本到平面文件,然后从平面文件读取到SQL Server,有关详细信息,请参阅以下链接:

(2) 使用IronPython

IronPython is an open-source implementation of the Python programming language which is tightly integrated with the .NET Framework. IronPython can use the .NET Framework and Python libraries, and other .NET languages can use Python code just as easily.

您可以使用脚本组件集成IronPython库:

我以前没用过这个图书馆,不知道能不能帮上忙。我读过@billingc写的comment链接到下面的答案,其中包含了一个关于如何做到这一点的惊人指南:

参考文献

如果Python引擎安装在尝试运行此脚本的服务器上,则可以使用executeprocess任务并调用python.exe. 将.py文件作为参数传递给任务,它也将运行脚本。在

相关问题 更多 >

    热门问题