尝试在 C# 中的 IronPython 中导入 pyodbc 库 [英] trying to import pyodbc library in IronPython in C#

查看:82
本文介绍了尝试在 C# 中的 IronPython 中导入 pyodbc 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 IronPhyton 脚本语言嵌入到 C# 项目中.我希望让用户在我的 C# 项目中使用 IronPhyton 编写代码.

I am trying to embed IronPhyton scripting language into the C# project. I am hoping to let users write code with IronPhyton in my C# project.

我需要让用户使用 IronPhyton 从数据库中获取数据,但我找不到导入 pyodbc 库的方法.我应该把库文件放在哪里以便 IronPyhton 建立连接?我应该将库添加到 Visual Studio 中吗?我搞不清楚了.该库不是 DLL 文件,而是一堆 .pdb 文件.

I need to let users get data from database with IronPhyton, but I couldnt find a way to import the pyodbc library. Where should I put the library files in order for IronPyhton to make a connection? Should I add the library into the Visual Studio? I am lost. The library is not a DLL file, it is bunch of .pdb files.

下面的代码是 IronPhyton.

this code below is IronPhyton.

import pyodbc
cnxn = pyodbc.connect("DRIVER={SQL Server};SERVER=SOME-PC;DATABASE=my_db")
cursor = cnxn.cursor()

推荐答案

我认为您不能在 IronPython 中使用使用本机库(DLL 或其他二进制文件)的 Python 库.而不是尝试使用 pyodbc 使用 .NET 连接到数据库的方式.参见 http://www.ironpython.info/index.php?title=Databases_with_Odbc .我已经使用 Oracle ODBC 连接对其进行了测试,并且可以正常工作.

I think you cannot use Python libraries that use native libraries (DLLs or other binary files) in IronPython. Instead of trying to use pyodbc use .NET ways of connecting to database. See http://www.ironpython.info/index.php?title=Databases_with_Odbc . I have tested it with Oracle ODBC connections and it works.

在 Jython 中存在类似的问题,您可以在其中使用 JDBC 驱动程序或纯 Python 库.

Similar problem is in Jython where you can use JDBC drivers or pure Python libaries.

这篇关于尝试在 C# 中的 IronPython 中导入 pyodbc 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆