Python pymssql.connect() Examples
The following are 30
code examples of pymssql.connect().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pymssql
, or try the search function
.
Example #1
Source File: mssql.py From airflow with Apache License 2.0 | 7 votes |
def get_conn(self): """ Returns a mssql connection object """ conn = self.get_connection(self.mssql_conn_id) # pylint: disable=no-member # pylint: disable=c-extension-no-member conn = pymssql.connect( server=conn.host, user=conn.login, password=conn.password, database=self.schema or conn.schema, port=conn.port, ) return conn
Example #2
Source File: mssqlconnection.py From sqlobject with GNU Lesser General Public License v2.1 | 6 votes |
def makeConnection(self): if self.driver in ('odbc', 'pyodbc', 'pypyodbc'): self.debugWriter.write( "ODBC connect string: " + self.odbc_conn_str) timeout = self.timeout if timeout: kw = dict(timeout=timeout) else: kw = dict() conn = self.module.connect(self.odbc_conn_str, **kw) if timeout: conn.timeout = timeout else: conn_descr = self.make_conn_str(self) if isinstance(conn_descr, dict): conn = self.dbconnection(**conn_descr) else: conn = self.dbconnection(conn_descr) cur = conn.cursor() cur.execute('SET ANSI_NULLS ON') cur.execute("SELECT CAST('12345.21' AS DECIMAL(10, 2))") self.decimalSeparator = str(cur.fetchone()[0])[-3] cur.close() return conn
Example #3
Source File: mssql.py From Commander with MIT License | 6 votes |
def rotate(record, newpassword): """ Grab any required fields from the record """ user = record.login oldpassword = record.password result = False host = record.get('cmdr:host') db = record.get('cmdr:db') connection = '' try: # Connect to the database connection = pymssql.connect(host=host, user=user, password=oldpassword, db=db) with connection.cursor() as cursor: print("Connected to %s"%(host)) # Create a new record sql = 'ALTER LOGIN %s WITH PASSWORD="%s";'%(user, newpassword) cursor.execute(sql) # connection is not autocommit by default. So you must commit to save # your changes. connection.commit() record.password = newpassword result = True except: print("Error during connection to Microsoft SQL server") finally: if connection: connection.close() return result
Example #4
Source File: check_mssql_database.py From check_mssql_collection with GNU General Public License v2.0 | 6 votes |
def main(): options = parse_args() mssql, total, host = connect_db(options) if options.mode =='test': run_tests(mssql, options, host) elif not options.mode or options.mode == 'time2connect': return_nagios( options, stdout='Time to connect was %ss', label='time', unit='s', result=total ) else: execute_query(mssql, options, host)
Example #5
Source File: check_mssql_server.py From check_mssql_collection with GNU General Public License v2.0 | 6 votes |
def main(): options = parse_args() mssql, total, host = connect_db(options) if options.mode =='test': run_tests(mssql, options, host) elif not options.mode or options.mode == 'time2connect': return_nagios( options, stdout='Time to connect was %ss', label='time', unit='s', result=total ) else: execute_query(mssql, options, host)
Example #6
Source File: connector.py From POC-EXP with GNU General Public License v3.0 | 5 votes |
def connect(self): self.initConnection() try: self.connector = pymssql.connect(host="%s:%d" % (self.hostname, self.port), user=self.user, password=self.password, database=self.db, login_timeout=conf.timeout, timeout=conf.timeout) except (pymssql.InterfaceError, pymssql.OperationalError), msg: raise SqlmapConnectionException(msg)
Example #7
Source File: mssql.py From Allscanner with MIT License | 5 votes |
def mssqlburp(ip,port): addr = (ip,int(port)) with open('mssql\user.txt') as user: users = user.readlines() user.close() with open('mssql\pass.txt') as passs: passwords = passs.readlines() passs.close() sock_1433 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock_1433.settimeout(1) sock_1433.connect(addr) host = ip + ':' + str(port) for un in users: un = un.strip() for pwd in passwords: pwd = pwd.strip() try: conn = pymssql.connect(host=host,user=un,password=pwd) sys.stdout.write('%s:%d has MicroSoft SQL WeakPass, %s:%s\n' % (ip, port, un, pwd)) except Exception,e: continue except: sock_1433.close()
Example #8
Source File: connector.py From POC-EXP with GNU General Public License v3.0 | 5 votes |
def connect(self): self.initConnection() try: self.connector = pymssql.connect(host="%s:%d" % (self.hostname, self.port), user=self.user, password=self.password, database=self.db, login_timeout=conf.timeout, timeout=conf.timeout) except pymssql.OperationalError, msg: raise SqlmapConnectionException(msg)
Example #9
Source File: check_mssql_database.py From check_mssql_collection with GNU General Public License v2.0 | 5 votes |
def connect_db(options): host = options.hostname if options.instance: host += "\\" + options.instance elif options.port: host += ":" + options.port start = time.time() mssql = pymssql.connect(host = host, user = options.user, password = options.password, database=options.table) total = time.time() - start return mssql, total, host
Example #10
Source File: check_mssql_server.py From check_mssql_collection with GNU General Public License v2.0 | 5 votes |
def connect_db(options): host = options.hostname if options.instance: host += "\\" + options.instance elif options.port: host += ":" + options.port start = time.time() mssql = pymssql.connect(host = host, user = options.user, password = options.password, database='master') total = time.time() - start return mssql, total, host
Example #11
Source File: mssql.py From enumdb with GNU General Public License v3.0 | 5 votes |
def connect(self, host, port, user, passwd, verbose=False): try: con = pymssql.connect(server=host, port=port, user=user, password=passwd, login_timeout=3, timeout=15) print_success("Connection established {}:{}@{}".format(user, passwd, host)) return con except Exception as e: if verbose: print_failure("Login failed {}:{}@{}\t({})".format(user, passwd, host, e)) return False
Example #12
Source File: connector.py From EasY_HaCk with Apache License 2.0 | 5 votes |
def connect(self): self.initConnection() try: self.connector = pymssql.connect(host="%s:%d" % (self.hostname, self.port), user=self.user, password=self.password, database=self.db, login_timeout=conf.timeout, timeout=conf.timeout) except (pymssql2.Error, _mssql.MssqlDatabaseException), msg: raise SqlmapConnectionException(msg)
Example #13
Source File: connector.py From EasY_HaCk with Apache License 2.0 | 5 votes |
def connect(self): self.initConnection() try: self.connector = pymssql.connect(host="%s:%d" % (self.hostname, self.port), user=self.user, password=self.password, database=self.db, login_timeout=conf.timeout, timeout=conf.timeout) except (pymssql.Error, _mssql.MssqlDatabaseException), msg: raise SqlmapConnectionException(msg)
Example #14
Source File: database.py From sweetest with Mozilla Public License 2.0 | 5 votes |
def fetchone(self, sql): try: self.cursor.execute(sql) data = self.cursor.fetchone() self.connect.commit() return data except: logger.exception('*** Fetchone failure ***') raise
Example #15
Source File: database.py From sweetest with Mozilla Public License 2.0 | 5 votes |
def fetchall(self, sql): try: self.cursor.execute(sql) data = self.cursor.fetchall() self.connect.commit() return data except: logger.exception('*** Fetchall failure ***') raise
Example #16
Source File: database.py From sweetest with Mozilla Public License 2.0 | 5 votes |
def execute(self, sql): try: self.cursor.execute(sql) self.connect.commit() except: logger.exception('*** Execute failure ***') raise
Example #17
Source File: database.py From sweetest with Mozilla Public License 2.0 | 5 votes |
def __del__(self): self.connect.close()
Example #18
Source File: fuzzer.py From libinjection-fuzzer with MIT License | 5 votes |
def db_connect(args): if args.type == "mysql" or args.type == "mariadb": import mysql.connector try: connection = mysql.connector.connect( user=args.user, password=args.password, database=args.db) except mysql.connector.Error as err: print(colorize("red", "[ERROR] {}".format(err))) return None elif args.type == "mssql": import pymssql try: connection = pymssql.connect(server="localhost", database=args.db) except pymssql.Error as err: print(colorize("red", "[ERROR] {}".format(err))) return None elif args.type == "pgsql": import psycopg2 try: connection = psycopg2.connect( "dbname='{}' user='{}' password='{}'".format( args.db, args.user, args.password)) except psycopg2.Error as err: print(colorize("red", "[ERROR] {}".format(err))) return None elif args.type == "oracle": import cx_Oracle try: connection = cx_Oracle.connect( args.user, args.password, cx_Oracle.makedsn( '127.0.0.1', 1521, args.db), mode=cx_Oracle.SYSDBA) except cx_Oracle.Error as err: print(colorize("red", "[ERROR] {}".format(err))) return None return connection
Example #19
Source File: base.py From django-pymssql with MIT License | 5 votes |
def __get_dbms_version(self, make_connection=True): """ Returns the 'DBMS Version' string, or ''. If a connection to the database has not already been established, a connection will be made when `make_connection` is True. """ if not self.connection and make_connection: self.connect() with self.connection.cursor() as cursor: cursor.execute("SELECT SERVERPROPERTY('productversion')") return cursor.fetchone()[0]
Example #20
Source File: base.py From django-pymssql with MIT License | 5 votes |
def get_new_connection(self, conn_params): return Database.connect(**conn_params)
Example #21
Source File: flask_sapb1.py From Flask-SAPB1 with MIT License | 5 votes |
def cursorAdaptor(self): ctx = stack.top if ctx is not None: if not hasattr(ctx, 'msSQLCursorAdaptor'): ctx.msSQLCursorAdaptor = self.connect(type="CURSOR") return ctx.msSQLCursorAdaptor
Example #22
Source File: flask_sapb1.py From Flask-SAPB1 with MIT License | 5 votes |
def comAdaptor(self): ctx = stack.top if ctx is not None: if not hasattr(ctx, 'sapb1COMAdaptor'): ctx.sapb1COMAdaptor = self.connect(type="COM") return ctx.sapb1COMAdaptor
Example #23
Source File: flask_sapb1.py From Flask-SAPB1 with MIT License | 5 votes |
def connect(self, type=None): """Initiate the connect with SAP B1 and MS SQL server. """ if type == "COM": SAPbobsCOM = __import__(current_app.config['DIAPI'], globals(), locals(), [], -1) self.constants = getattr(SAPbobsCOM, "constants") Company = getattr(SAPbobsCOM, "Company") company = Company() company.Server = current_app.config['SERVER'] company.UseTrusted = False company.language = eval("self.constants." + current_app.config['LANGUAGE']) company.DbServerType = eval("self.constants." + current_app.config['DBSERVERTYPE']) company.CompanyDB = current_app.config['COMPANYDB'] company.UserName = current_app.config['B1USERNAME'] company.Password = current_app.config['B1PASSWORD'] company.Connect() log = "Open SAPB1 connection for " + company.CompanyName current_app.logger.info(log) return SAPB1COMAdaptor(company=company) elif type == "CURSOR": sqlSrvConn = pymssql.connect(current_app.config['SERVER'], current_app.config['DBUSERNAME'], current_app.config['DBPASSWORD'], current_app.config['COMPANYDB']) log = "Open SAPB1 DB connection" current_app.logger.info(log) return MSSQLCursorAdaptor(sqlSrvConn=sqlSrvConn) else: return None
Example #24
Source File: connector.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def connect(self): self.initConnection() try: self.connector = pymssql.connect(host="%s:%d" % (self.hostname, self.port), user=self.user, password=self.password, database=self.db, login_timeout=conf.timeout, timeout=conf.timeout) except pymssql.OperationalError, msg: raise SqlmapConnectionException(msg)
Example #25
Source File: connector.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def connect(self): self.initConnection() try: self.connector = pymssql.connect(host="%s:%d" % (self.hostname, self.port), user=self.user, password=self.password, database=self.db, login_timeout=conf.timeout, timeout=conf.timeout) except (pymssql.InterfaceError, pymssql.OperationalError), msg: raise SqlmapConnectionException(msg)
Example #26
Source File: connector.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def connect(self): self.initConnection() try: self.connector = pymssql.connect(host="%s:%d" % (self.hostname, self.port), user=self.user, password=self.password, database=self.db, login_timeout=conf.timeout, timeout=conf.timeout) except pymssql.OperationalError, msg: raise SqlmapConnectionException(msg)
Example #27
Source File: connector.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def connect(self): self.initConnection() try: self.connector = pymssql.connect(host="%s:%d" % (self.hostname, self.port), user=self.user, password=self.password, database=self.db, login_timeout=conf.timeout, timeout=conf.timeout) except (pymssql.InterfaceError, pymssql.OperationalError), msg: raise SqlmapConnectionException(msg)
Example #28
Source File: connector.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def connect(self): self.initConnection() try: self.connector = pymssql.connect(host="%s:%d" % (self.hostname, self.port), user=self.user, password=self.password, database=self.db, login_timeout=conf.timeout, timeout=conf.timeout) except pymssql.OperationalError, msg: raise SqlmapConnectionException(msg)
Example #29
Source File: connector.py From NoobSec-Toolkit with GNU General Public License v2.0 | 5 votes |
def connect(self): self.initConnection() try: self.connector = pymssql.connect(host="%s:%d" % (self.hostname, self.port), user=self.user, password=self.password, database=self.db, login_timeout=conf.timeout, timeout=conf.timeout) except (pymssql.InterfaceError, pymssql.OperationalError), msg: raise SqlmapConnectionException(msg)
Example #30
Source File: peewee_mssql.py From peewee-mssql with MIT License | 5 votes |
def _connect(self, database, **kwargs): if not pymssql: raise ImproperlyConfigured('pymssql must be installed') if kwargs.pop('use_legacy_datetime', False): self.field_overrides['datetime'] = 'datetime' self.field_overrides['date'] = 'nvarchar(15)' self.field_overrides['time'] = 'nvarchar(10)' return pymssql.connect(database=database, **kwargs)