Cannot import csv to mssql
Opened this issue · 2 comments
iuria21 commented
Hi, I'm trying to import a csv to a mssql server and I get the following error:
creating mysql.csv ok
loading mysql.csv ok
---------------------------------------------------------------------------
MSSQLDatabaseException Traceback (most recent call last)
src/pymssql.pyx in pymssql.Cursor.execute()
src/_mssql.pyx in _mssql.MSSQLConnection.execute_query()
src/_mssql.pyx in _mssql.MSSQLConnection.execute_query()
src/_mssql.pyx in _mssql.MSSQLConnection.format_and_run_query()
src/_mssql.pyx in _mssql.check_cancel_and_raise()
src/_mssql.pyx in _mssql.maybe_raise_MSSQLDatabaseException()
MSSQLDatabaseException: (4860, b'Cannot bulk load. The file "mysql.csv" does not exist.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n')
During handling of the above exception, another exception occurred:
OperationalError Traceback (most recent call last)
~/codigos/thomson/myenv/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args)
1245 self.dialect.do_execute(
-> 1246 cursor, statement, parameters, context
1247 )
~/codigos/thomson/myenv/lib/python3.6/site-packages/sqlalchemy/engine/default.py in do_execute(self, cursor, statement, parameters, context)
580 def do_execute(self, cursor, statement, parameters, context=None):
--> 581 cursor.execute(statement, parameters)
582
src/pymssql.pyx in pymssql.Cursor.execute()
OperationalError: (4860, b'Cannot bulk load. The file "mysql.csv" does not exist.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n')
The above exception was the direct cause of the following exception:
OperationalError Traceback (most recent call last)
<ipython-input-11-267ba832f344> in <module>
5 #uri_mssql = f'mysql+mysqlconnector://{user}:{passW}@{host}:1433/{db}'
6
----> 7 d6tstack.utils.pd_to_mssql(df, uri_mssql, 'prueba', if_exists='replace') # experimental
~/codigos/thomson/myenv/lib/python3.6/site-packages/d6tcollect/__init__.py in wrapper(*args, **kwargs)
78 payload['exceptionMsg'] = str(e)
79 _submit(payload)
---> 80 raise e
81
82 return wrapper
~/codigos/thomson/myenv/lib/python3.6/site-packages/d6tcollect/__init__.py in wrapper(*args, **kwargs)
72 _submit(payload)
73 try:
---> 74 return func(*args, **kwargs)
75 except Exception as e:
76 payload['event'] = 'exception'
~/codigos/thomson/myenv/lib/python3.6/site-packages/d6tstack/utils.py in pd_to_mssql(df, uri, table_name, schema_name, if_exists, tmpfile)
188 table_name = '{}.{}'.format(schema_name,table_name)
189 sql_load = "BULK INSERT {} FROM '{}';".format(table_name, tmpfile)
--> 190 sql_engine.execute(sql_load)
191
192 os.remove(tmpfile)
~/codigos/thomson/myenv/lib/python3.6/site-packages/sqlalchemy/engine/base.py in execute(self, statement, *multiparams, **params)
2180
2181 connection = self._contextual_connect(close_with_result=True)
-> 2182 return connection.execute(statement, *multiparams, **params)
2183
2184 def scalar(self, statement, *multiparams, **params):
~/codigos/thomson/myenv/lib/python3.6/site-packages/sqlalchemy/engine/base.py in execute(self, object_, *multiparams, **params)
974 """
975 if isinstance(object_, util.string_types[0]):
--> 976 return self._execute_text(object_, multiparams, params)
977 try:
978 meth = object_._execute_on_connection
~/codigos/thomson/myenv/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_text(self, statement, multiparams, params)
1147 parameters,
1148 statement,
-> 1149 parameters,
1150 )
1151 if self._has_events or self.engine._has_events:
~/codigos/thomson/myenv/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args)
1248 except BaseException as e:
1249 self._handle_dbapi_exception(
-> 1250 e, statement, parameters, cursor, context
1251 )
1252
~/codigos/thomson/myenv/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _handle_dbapi_exception(self, e, statement, parameters, cursor, context)
1474 util.raise_from_cause(newraise, exc_info)
1475 elif should_wrap:
-> 1476 util.raise_from_cause(sqlalchemy_exception, exc_info)
1477 else:
1478 util.reraise(*exc_info)
~/codigos/thomson/myenv/lib/python3.6/site-packages/sqlalchemy/util/compat.py in raise_from_cause(exception, exc_info)
396 exc_type, exc_value, exc_tb = exc_info
397 cause = exc_value if exc_value is not exception else None
--> 398 reraise(type(exception), exception, tb=exc_tb, cause=cause)
399
400
~/codigos/thomson/myenv/lib/python3.6/site-packages/sqlalchemy/util/compat.py in reraise(tp, value, tb, cause)
150 value.__cause__ = cause
151 if value.__traceback__ is not tb:
--> 152 raise value.with_traceback(tb)
153 raise value
154
~/codigos/thomson/myenv/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args)
1244 if not evt_handled:
1245 self.dialect.do_execute(
-> 1246 cursor, statement, parameters, context
1247 )
1248 except BaseException as e:
~/codigos/thomson/myenv/lib/python3.6/site-packages/sqlalchemy/engine/default.py in do_execute(self, cursor, statement, parameters, context)
579
580 def do_execute(self, cursor, statement, parameters, context=None):
--> 581 cursor.execute(statement, parameters)
582
583 def do_execute_no_params(self, cursor, statement, context=None):
src/pymssql.pyx in pymssql.Cursor.execute()
OperationalError: (pymssql.OperationalError) (4860, b'Cannot bulk load. The file "mysql.csv" does not exist.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n')
[SQL: BULK INSERT prueba FROM 'mysql.csv';]
(Background on this error at: http://sqlalche.me/e/e3q8)
CIBERCOP20001 commented
did you fix it?
datacurse commented
still unsolved?