Exemple #1
0
 def connect(self, **kwargs):
     environ['TDSDUMPCONFIG'] = config_dump_path
     try:
         _mssql.connect(**kwargs)
         assert False
     except _mssql.MSSQLDriverException as e:
         # we get this when the name of the server is not valid
         if 'Connection to the database failed' not in str(e):
             raise
     except _mssql.MSSQLDatabaseException as e:
         # we get this when the name or IP can be obtained but the connection
         # can not be made
         if e.args[0][0] != 20009:
             raise
     with open(config_dump_path, 'r') as fh:
         return fh.read()
Exemple #2
0
    def test_conn_props_override(self):
        conn = mssqlconn(conn_properties='SET TEXTSIZE 2147483647')
        conn.close()

        conn = mssqlconn(conn_properties='SET TEXTSIZE 2147483647;')
        conn.close()

        conn = mssqlconn(
            conn_properties='SET TEXTSIZE 2147483647;SET ANSI_NULLS ON;')
        conn.close()

        conn = mssqlconn(
            conn_properties='SET TEXTSIZE 2147483647;SET ANSI_NULLS ON')
        conn.close()

        conn = mssqlconn(conn_properties='SET TEXTSIZE 2147483647;'
                         'SET ANSI_NULLS ON;')
        conn.close()

        conn = mssqlconn(
            conn_properties=['SET TEXTSIZE 2147483647;', 'SET ANSI_NULLS ON'])
        conn.close()
        self.assertRaises(_mssql.MSSQLDriverException,
                          mssqlconn,
                          conn_properties='BOGUS SQL')

        conn = _mssql.connect(conn_properties='SET TEXTSIZE 2147483647',
                              server=server,
                              user=username,
                              password=password)
        conn.close()
Exemple #3
0
def mssqlconn(conn_properties=None):
    return _mssql.connect(server=config.server,
                          user=config.user,
                          password=config.password,
                          database=config.database,
                          port=config.port,
                          conn_properties=conn_properties)
Exemple #4
0
 def makeBackup(self, database, type, path) :
     print("making backup: %s" % (database,))
     command = self.commandTemplate \
                     .replace("%dbname%", database) \
                     .replace("%type%", type) \
                     .replace("%path%", path)
     with _mssql.connect(server=self.server, user=self.username, password=self.password, database=database) as db :
         db.execute_non_query(command)
Exemple #5
0
def backupDatabase(dbname):
    print("making backup: %s" % (dbname, ))
    command = settings['sql']['command_full']['query'].replace(
        "%dbname%", dbname).replace("%path%", settings['path']['local'])
    with _mssql.connect(server="localhost",
                        user=settings['sql']['username'],
                        password=settings['sql']['password'],
                        database=dbname) as db:
        db.execute_non_query(command)
    return
Exemple #6
0
    def test_repeated_failed_connections(self):
        # This is a test for https://github.com/pymssql/pymssql/issues/145
        # (Repeated failed connections result in error string getting longer
        # and longer)

        last_exc_message = None
        for i in range(5):
            try:
                _mssql.connect(server='agithub.com',
                               port=80,
                               user='******',
                               password='******',
                               database='tempdb')
            except Exception as exc:
                exc_message = exc.args[0][1]

                if last_exc_message:
                    self.assertEqual(exc_message, last_exc_message)

                last_exc_message = exc_message
Exemple #7
0
 async def connection(self):
     """
     Get a connection
     """
     self._connection = None
     self._connected = False
     try:
         self._params["appname"] = self.application_name
         self._params["charset"] = self._charset.upper()
         self._params["tds_version"] = "7.3"
         if self._server_settings:
             self._params["conn_properties"] = self._server_settings
         self._connection = _mssql.connect(**self._params)
         if self._connection.connected:
             self._connected = True
             self._initialized_on = time.time()
     except Exception as err:
         print(err)
         self._connection = None
         self._cursor = None
         raise ProviderError("connection Error, Terminated: {}".format(
             str(err)))
     finally:
         return self
Exemple #8
0
 def connect(self, **kwargs):
     environ['TDSDUMPCONFIG'] = config_dump_path
     environ['TDSDUMP'] = dump_path
     _mssql.connect(**kwargs)
     with open(config_dump_path, 'r') as fh:
         return fh.read()
def connect(sql_server,database,user,password):
    "helper function for creating a new db connection"
    conn = _mssql.connect(server=sql_server, database=database, user=user, password=password)
    return conn
Exemple #10
0
# -*- coding: utf-8 -*-
#!/usr/bin/python
"""

"""

from pymssql import _mssql

test_str = 'testing' * 1000

for i in xrange(0, 1000):
    cnx = _mssql.connect('ukplcdbtest01', 'sa', 'deter101', charset='cp1252')
    cnx.select_db('tempdb')
    proc = cnx.init_procedure('pymssqlTestVarchar')
    proc.bind(test_str, _mssql.SQLVARCHAR, '@ivarchar')
    proc.bind(None, _mssql.SQLVARCHAR, '@ovarchar', output=True)
    return_value = proc.execute()
    cnx.close()