import pyodbc #DRIVER={FreeTDS};SERVER=10.16.9.191;PORT=1433;TDS_VERSION=7.3;UID=datazone\scalearc_admin;timeout=2;Trusted_Connection=no;UseNTLMv2=yes;PWD=; UID="datazone\scalearc_admin" servers=('10.16.9.165','10.16.9.251','10.16.9.191','10.16.9.192') PWD="PLEASE ENTER PASSWORD IN SCRIPT" servers_host=('DZSQL18','DZSQL23','DZSQL24','DZSQL25') #UID="sa" #PWD="Yolmeturda3!" #servers_host=('vm-00016f4c.vdi-vm.devfactory.com','vm-00016f4e.vdi-vm.devfactory.com') #servers=('10.162.3.147','10.162.3.191') for server in servers: print("UID is %s" %UID) print("PWD IS %s" %PWD) print server conn = pyodbc.connect('DRIVER={FreeTDS};SERVER='+server+';PORT=1433;TDS_VERSION=7.3;UID='+UID+';timeout=2;Trusted_Connection=no;UseNTLMv2=yes;PWD='+PWD+';') cursor = conn.cursor() #cursor.execute('select * from master.dbo.MSreplication_options;') cursor.execute('select endpoint_url from sys.availability_replicas where replica_server_name = (select primary_replica from sys.dm_hadr_availability_group_states);') for row in cursor: print('row = %r' % (row,)) cursor.execute('select replica_server_name,primary_role_allow_connections_desc,secondary_role_allow_connections_desc from sys.availability_replicas;') for row in cursor: print('row = %r' % (row,)) cursor.execute('select endpoint_url,primary_role_allow_connections_desc,secondary_role_allow_connections_desc from sys.availability_replicas;') for row in cursor: print('row = %r' % (row,)) for host in servers_host: print("UID is %s" %UID) print("PWD IS %s" %PWD) print host conn = pyodbc.connect('DRIVER={FreeTDS};SERVER='+host+';PORT=1433;TDS_VERSION=7.3;UID='+UID+';timeout=2;Trusted_Connection=no;UseNTLMv2=yes;PWD='+PWD+';') cursor = conn.cursor() #cursor.execute('select * from master.dbo.MSreplication_options;') cursor.execute('select endpoint_url from sys.availability_replicas where replica_server_name = (select primary_replica from sys.dm_hadr_availability_group_states);') for row in cursor: print('row = %r' % (row,)) cursor.execute('select replica_server_name,primary_role_allow_connections_desc,secondary_role_allow_connections_desc from sys.availability_replicas;') for row in cursor: print('row = %r' % (row,)) cursor.execute('select endpoint_url,primary_role_allow_connections_desc,secondary_role_allow_connections_desc from sys.availability_replicas;') for row in cursor: print('row = %r' % (row,))