简体   繁体   English

pyodbc到MS Access的连接字符串; 可以使用IP地址吗?

[英]pyodbc to MS access connection string; can it use IP address?

I compile the program to connect to ms access database as follow: 我编译程序以连接到ms Access数据库,如下所示:

conn_string = (
    r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
    r'DBQ=C:\folder_name\EVT_LOG.mdb;')

And this works fine as intended. 这按预期工作正常。

Then I try to deploy into remote server/client situation where the database is located in the client and server have to access it, so I revamped the connection string as follow: 然后,我尝试将数据库部署在客户端中并且服务器必须访问它的情况下,将其部署到远程服务器/客户端中,因此我如下修改了连接字符串:

conn_string = (
    r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
    r'DBQ=\\10.80.112.81\folder_name\EVT_LOG.mdb;')

This one got pyodbc.error data source name not found. 找不到此pyodbc.error数据源名称。 Any idea on doing this pyodbc on remote database? 对在远程数据库上执行此pyodbc有任何想法吗?

Yes, an IP address can be used as the server name in a UNC path. 是的,IP地址可以用作UNC路径中的服务器名称。 The database file must be accessible from the Windows file system on the machine running the Python script, and its location can be specified as a local file ... 必须从运行Python脚本的计算机上的Windows文件系统中访问数据库文件,并且可以将其位置指定为本地文件...

C:\folder_name\EVT_LOG.mdb

... a file on a network share mapped to a drive letter ... ...网络共享上映射到驱动器号的文件...

W:\some_folder\EVT_LOG.mdb

... a UNC path that uses the server name ... ...使用服务器名称的UNC路径...

\\server_name\share_name\some_folder\EVT_LOG.mdb

... or a UNC path that uses the server IP address ... ...或使用服务器IP地址的UNC路径...

\\10.80.112.81\share_name\some_folder\EVT_LOG.mdb

Note, however, that Windows file sharing (sometimes referred to as SMB or CIFS) is almost never directly accessible over the Internet, so for practical purposes the server that is hosting the database file must either be on your local network, on a secure WAN, or made available over a VPN connection. 但是请注意,Windows文件共享(有时称为SMB或CIFS)几乎永远不能通过Internet直接访问,因此,出于实际目的,承载数据库文件的服务器必须位于本地网络上,并且位于安全WAN上,或通过VPN连接可用。 In each of those cases it is very likely that the server will be available by name, so the IP form of the UNC path is not often used. 在每种情况下,很有可能按名称提供服务器,因此不经常使用UNC路径的IP形式。

Also remember that the file must be accessible using Windows file sharing, not some other Internet protocol like HTTP, FTP, etc.. 还请记住,必须使用Windows文件共享(而不是HTTP,FTP等某些其他Internet协议)来访问文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM