Python打开Microsoft SQL Server MDF文件 [英] Python open Microsoft SQL Server MDF file

查看:358
本文介绍了Python打开Microsoft SQL Server MDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Python中打开Microsoft SQL Server MDF文件?



编辑



我已经已尝试 pyodbc.connect ,但这需要合法的服务器连接,您不能简单地打开MDF文件。

  pyodbc.connect(driver ='{SQL Server}',dbq = r'c:\database.mdf')


(就像您对MDB文件所做的那样。)


pyodbc错误:没有提供DSN或SERVER关键字


好的-

  pyodbc.connect(driver ='{SQL Server}',dsn = r'c:\database.mdf')




pyodbc。错误:找不到数据源名称


我要做的就是列出其架构,然后列出它。

解决方案

使用Python的事实是与此处有关:.mdf文件是二进制数据库文件,只能由将其附加到SQL Server并通过服务器实例查询数据库。目前尚不清楚为什么这对您来说是个问题,因为pyodbc可以在SQL Server上正常运行(至少在Windows上),因此,如果这不能回答您的问题,则可能需要扩展您尝试做的事情以及原因您不能只是连接到SQL Server。



通常提到您的操作系统,Python版本,SQL Server版本等都是有用的。


How can I open an Microsoft SQL Server MDF file in Python?

Edit

I've tried pyodbc.connect but that requires a legitimate "server connection"—you can't simply open the MDF file—

pyodbc.connect(driver='{SQL Server}', dbq=r'c:\database.mdf')

(Like you'd do for MDB files.)

pyodbc.Error: Neither DSN or SERVER keyword supplied

Okay—

pyodbc.connect(driver='{SQL Server}', dsn=r'c:\database.mdf')

pyodbc.Error: Data source name not found

All I want to do is list its schema and then it.

解决方案

The fact that you're using Python isn't relevant here: an .mdf file is a binary database file that can only be accessed by attaching it to SQL Server and querying the database through the server instance. It's not clear why this is an issue for you, because pyodbc will work fine with SQL Server (on Windows, at least) so if this doesn't answer your question you may want to expand on what you're trying to do and why you can't just connect to SQL Server.

And mentioning your OS, Python version, SQL Server version etc. is usually helpful.

这篇关于Python打开Microsoft SQL Server MDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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