Query SQL Browser for port used by named instance
Project description
sqlserverport
A simple Python module to query the SQL Browser service for the port number of a SQL Server instance. The Linux implementation of Microsoft's "ODBC Driver xx for SQL Server" is (still) unable to resolve instance names, so Windows users can just do
import pyodbc
serverspec = r'myserver\SQLEXPRESS'
conn = pyodbc.connect('DRIVER=ODBC Driver 17 for SQL Server;SERVER={};...'.format(serverspec))
but that won't work on Linux. This module lets us do
import pyodbc
import sqlserverport
servername = 'myserver'
serverspec = '{0},{1}'.format(
servername,
sqlserverport.lookup(servername, 'SQLEXPRESS'))
conn = pyodbc.connect('DRIVER=ODBC Driver 17 for SQL Server;SERVER={};...'.format(serverspec))
Installing
pip install sqlserverport
Example
# example.py
import sqlserverport
# test data
server_name = "192.168.0.103"
instance_name = "SQLEXPRESS"
try:
result = r"Instance {0}\{1} is listening on port {2}.".format(
server_name,
instance_name,
sqlserverport.lookup(server_name, instance_name),
)
except sqlserverport.BrowserError as err:
result = err.message
except sqlserverport.NoTcpError as err:
result = err.message
print(result)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sqlserverport-1.0.1.tar.gz
(3.4 kB
view hashes)
Built Distribution
Close
Hashes for sqlserverport-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa425ae398929fc464eb9c3c56b88b9758b1fdd70d35652e1cc46999509fd559 |
|
MD5 | d02b676b763bccef6a742d357ae0ea37 |
|
BLAKE2b-256 | c1ce3b692ffaa2aa906c1dab6816d50a384b5cdf0cbc53f802bfd6d04f926643 |