简体   繁体   中英

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

I compile the program to connect to ms access database as follow:

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. Any idea on doing this pyodbc on remote database?

Yes, an IP address can be used as the server name in a UNC path. 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 ...

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 ...

\\server_name\share_name\some_folder\EVT_LOG.mdb

... or a UNC path that uses the server IP address ...

\\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. 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.

Also remember that the file must be accessible using Windows file sharing, not some other Internet protocol like HTTP, FTP, etc..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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