How to use the pymssql.OperationalError function in pymssql

To help you get started, we’ve selected a few pymssql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sqlmapproject / sqlmap / plugins / dbms / mssqlserver / connector.py View on Github external
def select(self, query):
        retVal = None

        if self.execute(query):
            retVal = self.fetchall()

            try:
                self.connector.commit()
            except pymssql.OperationalError:
                pass

        return retVal
github NagiosEnterprises / check_mssql_collection / check_mssql_server.py View on Github external
for mode in list(MODES.keys()):
        total += 1
        options.mode = mode
        try:
            execute_query(mssql, options, host)
        except NagiosReturn:
            print("%s passed!" % mode)
        except Exception as e:
            failed += 1
            print("%s failed with: %s" % (mode, e))
    print('%d/%d tests failed.' % (failed, total))
    
if __name__ == '__main__':
    try:
        main()
    except pymssql.OperationalError as e:
        print(e)
        sys.exit(3)
    except pymssql.InterfaceError as e:
        print(e)
        sys.exit(3)
    except IOError as e:
        print(e)
        sys.exit(3)
    except NagiosReturn as e:
        print(e.message)
        sys.exit(e.code)
    except Exception as e:
        print(type(e))
        print("Caught unexpected error. This could be caused by your sysperfinfo not containing the proper entries for this query, and you may delete this service check.")
        sys.exit(3)
github sqlmapproject / sqlmap / plugins / dbms / sybase / connector.py View on Github external
def select(self, query):
        retVal = None

        if self.execute(query):
            retVal = self.fetchall()

            try:
                self.connector.commit()
            except pymssql.OperationalError:
                pass

        return retVal
github awsdocs / aws-doc-sdk-examples / lambda_functions / secretsmanager / RDSSQLServer-Singleuser.py View on Github external
"""
    # Parse and validate the secret JSON string
    port = str(secret_dict['port']) if 'port' in secret_dict else '1433'
    dbname = secret_dict['dbname'] if 'dbname' in secret_dict else 'master'

    # Try to obtain a connection to the db
    try:
        conn = pymssql.connect(server=secret_dict['host'],
                               user=secret_dict['username'],
                               password=secret_dict['password'],
                               database=dbname,
                               port=port,
                               login_timeout=5,
                               as_dict=True)
        return conn
    except pymssql.OperationalError:
        return None

github pymssql / pymssql / pymssql.py View on Github external
def fetchone(self):
		"""
		Fetch the next row of a query result, returning a tuple,
		or None when no more data is available. Raises OperationalError
		if previous call to execute*() did not produce any result set
		or no call was issued yet.
		"""
		if self._source.get_header() == None:
			raise OperationalError, "No data available."

		try:
			if self.as_dict:
				row = iter(self._source).next()
				self._rownumber += 1
				return row
			else:
				row = iter(self._source).next()
				self._rownumber += 1
				return tuple([row[r] for r in sorted(row.keys()) if type(r) == int])

		except StopIteration:
			return None
		except _mssql.MssqlDatabaseException, e:
			raise OperationalError, e[0]
		except _mssql.MssqlDriverException, e:
github NMGRL / pychron / pychron / database / tasks / connection_preferences.py View on Github external
cur.execute(sql)
            records = cur.fetchall()

        except BaseException:
            pass
    elif kind == 'mssql':
        import pymssql
        if exclude is None:
            exclude = ('master', 'tempdb', 'model', 'msdb')
        try:
            conn = pymssql.connect(host, user, password, timeout=1)
            cur = conn.cursor()
            sql = 'SELECT * FROM sys.databases'
            cur.execute(sql)
            records = cur.fetchall()
        except pymssql.OperationalError:
            pass

    names = [di[0] for di in records if di[0] not in exclude]
    return names
github guardicore / monkey / monkey / infection_monkey / exploit / mssqlexec.py View on Github external
"""
        # Main loop
        # Iterates on users list
        for user, password in users_passwords_pairs_list:
            try:
                # Core steps
                # Trying to connect
                conn = pymssql.connect(host, user, password, port=port, login_timeout=self.LOGIN_TIMEOUT)
                LOG.info(
                    'Successfully connected to host: {0}, using user: {1}, password (SHA-512): {2}'.format(
                        host, user, self._config.hash_sensitive_data(password)))
                self.add_vuln_port(MSSQLExploiter.SQL_DEFAULT_TCP_PORT)
                self.report_login_attempt(True, user, password)
                cursor = conn.cursor()
                return cursor
            except pymssql.OperationalError:
                self.report_login_attempt(False, user, password)
                # Combo didn't work, hopping to the next one
                pass

        LOG.warning('No user/password combo was able to connect to host: {0}:{1}, '
                    'aborting brute force'.format(host, port))
        raise FailedExploitationError("Bruteforce process failed on host: {0}".format(self.host.ip_addr))
github aws-samples / aws-secrets-manager-rotation-lambdas / SecretsManagerRDSSQLServerRotationSingleUser / lambda_function.py View on Github external
"""
    # Parse and validate the secret JSON string
    port = str(secret_dict['port']) if 'port' in secret_dict else '1433'
    dbname = secret_dict['dbname'] if 'dbname' in secret_dict else 'master'

    # Try to obtain a connection to the db
    try:
        conn = pymssql.connect(server=secret_dict['host'],
                               user=secret_dict['username'],
                               password=secret_dict['password'],
                               database=dbname,
                               port=port,
                               login_timeout=5,
                               as_dict=True)
        return conn
    except pymssql.OperationalError:
        return None