Every line of 'python connect to sql server' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
15 def connect(odbc_conn_str): 16 """Connect to a SQL database using an ODBC connection string""" 17 return db.connect(odbc_conn_str)
171 def connect(self, db, host, user, password): 172 assert False
108 def connect(self, dbname, superuser=False, autocommit=True): 109 """Create a pscopg2 connection to a database and return it. 110 111 dbname: The database to connect to. 112 superuser: Set to True to connect as the superuser, otherwise 113 connect as the user. 114 autocommit: Set to False to turn off autocommit, otherwise 115 autocommit will be turned on.""" 116 117 user = (self.superuser if superuser else self.user) 118 dsn = ("dbname=%s host=%s port=%s user=%s connect_timeout=%s" % 119 (dbname, self.host, self.port, user, CONNECT_TIMEOUT)) 120 conn = psycopg2.connect(dsn) 121 conn.autocommit = autocommit 122 123 return conn
6 def connect(hostname, username, password, database): 7 global db 8 db=mdb.connect(hostname, username, password, database) 9 return db
565 def _sql_connect(self, **kwargs): 566 """Attempt to establish a connection with this site's SQL database. 567 568 oursql.connect() will be called with self._sql_data as its kwargs. 569 Any kwargs given to this function will be passed to connect() and will 570 have precedence over the config file. 571 572 Will raise SQLError() if the module "oursql" is not available. oursql 573 may raise its own exceptions (e.g. oursql.InterfaceError) if it cannot 574 establish a connection. 575 """ 576 args = self._sql_data 577 for key, value in kwargs.iteritems(): 578 args[key] = value 579 if "read_default_file" not in args and "user" not in args and "passwd" not in args: 580 args["read_default_file"] = expanduser("~/.my.cnf") 581 elif "read_default_file" in args: 582 args["read_default_file"] = expanduser(args["read_default_file"]) 583 if "autoping" not in args: 584 args["autoping"] = True 585 if "autoreconnect" not in args: 586 args["autoreconnect"] = True 587 588 try: 589 self._sql_conn = oursql.connect(**args) 590 except ImportError: 591 e = "SQL querying requires the 'oursql' package: http://packages.python.org/oursql/" 592 raise exceptions.SQLError(e)
5 def connect_db(): 6 db_host = os.environ['db_host'] 7 db_user = os.environ['db_user'] 8 db_pw = os.environ['db_pw'] 9 db_name=os.environ['db_name'] 10 db = MySQLdb.connect(db_host, db_user, db_pw, db_name) 11 return db
257 def connect(self, database=None): 258 ''' 259 260 This method is responsible for defining the necessary interface to 261 connect to a SQL database. 262 263 ''' 264 265 self.conn = get_mariadb(self.host, self.user, self.passwd, database) 266 self.cursor = self.conn.cursor()
165 def connect(): 166 '''connect to database. 167 168 Use this method to connect to additional databases. 169 170 Returns a database connection. 171 ''' 172 173 dbh = sqlite3.connect(PARAMS["database_name"]) 174 statement = '''ATTACH DATABASE '%s' as annotations''' % ( 175 PARAMS["annotations_database"]) 176 cc = dbh.cursor() 177 cc.execute(statement) 178 cc.close() 179 180 return dbh
156 def ConnectDB(): 157 "Connect MySQLdb and Print version." 158 connect, cursor = None, None 159 while True: 160 try: 161 connect = MySQLdb.connect( 162 host=HOST, user=USER, passwd=PASSWD, db=DB, port=PORT, charset='utf8') 163 cursor = connect.cursor() 164 # cursor.execute("SELECT VERSION()") 165 # data = cursor.fetchone() 166 # print "Database version:%s\n"%data 167 break 168 except MySQLdb.Error, e: 169 print "Error %d: %s" % (e.args[0], e.args[1]) 170 return connect, cursor
35 def connect_to_db(): 36 db = MySQLdb.connect( 37 host=config.coverage_db_host, 38 user=config.coverage_db_user, 39 db=config.coverage_db_name, 40 passwd=config.coverage_db_password, 41 ) 42 db.autocommit(False) 43 return db