@@ -221,7 +221,6 @@ def create_cursor(self, name=None):
221221 def get_connection_params (self ):
222222 settings_dict = self .settings_dict
223223 if settings_dict ['NAME' ] == '' :
224- from django .core .exceptions import ImproperlyConfigured
225224 raise ImproperlyConfigured (
226225 "settings.DATABASES is improperly configured. "
227226 "Please supply the NAME value." )
@@ -242,28 +241,32 @@ def get_new_connection(self, conn_params):
242241 driver = options .get ('driver' , default_driver )
243242 dsn = options .get ('dsn' , None )
244243
245- # unixODBC uses string 'FreeTDS'; iODBC requires full path to lib
246- if driver == 'FreeTDS' or driver .endswith ('/libtdsodbc.so' ):
247- driver_is_freetds = True
248- else :
249- driver_is_freetds = False
250-
251244 # Microsoft driver names assumed here are:
252245 # * SQL Server
253246 # * SQL Native Client
254247 # * SQL Server Native Client 10.0/11.0
255- # * ODBC Driver 11 for SQL Server
248+ # * ODBC Driver 11/13 for SQL Server
256249 ms_drivers = re .compile ('.*SQL (Server$|(Server )?Native Client)' )
257250
251+ # available ODBC connection string keywords:
252+ # (Microsoft drivers for Windows)
253+ # https://docs.microsoft.com/en-us/sql/relational-databases/native-client/applications/using-connection-string-keywords-with-sql-server-native-client
254+ # (Microsoft drivers for Linux/Mac)
255+ # https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/connection-string-keywords-and-data-source-names-dsns
256+ # (FreeTDS)
257+ # http://www.freetds.org/userguide/odbcconnattr.htm
258258 cstr_parts = {}
259259 if dsn :
260260 cstr_parts ['DSN' ] = dsn
261261 else :
262262 # Only append DRIVER if DATABASE_ODBC_DSN hasn't been set
263263 cstr_parts ['DRIVER' ] = driver
264264
265- if ms_drivers .match (driver ) or driver_is_freetds and \
266- options .get ('host_is_server' , False ):
265+ if ms_drivers .match (driver ):
266+ if port :
267+ host = ',' .join ((host ,port ))
268+ cstr_parts ['SERVER' ] = host
269+ elif options .get ('host_is_server' , False ):
267270 if port :
268271 cstr_parts ['PORT' ] = str (port )
269272 cstr_parts ['SERVER' ] = host
0 commit comments