d6tstack icon indicating copy to clipboard operation
d6tstack copied to clipboard

Issue with database name with "\"

Open ledikari opened this issue 6 years ago • 1 comments

use a database name with \ it

#server name is someserver123\data
#database name = Comissions
#no user name and password because Trusted_Connection = yes

import pandas as pd
import d6tstack.utils

myfile = "myfile.csv" #absolute file
csv_file = pd.read_csv(my_file, iterator = True, chunksize= 20000, low_memory=False, dtype=str)

for i, chunk in enumerate(csv_file):
    d6tstack.utils.pd_to_mssql(chunk , 'mssql+pymssql://someserver123\data/Comissions', 'dbo.mydb', if_exists="append")

will yield error

UserWarning: .pd_to_mssql() is experimental, if any problems please raise an issue on https://github.com/d6t/d6tstack/issues or make a pull request warnings.warn('.pd_to_mssql() is experimental, if any problems please raise an issue on https://github.com/d6t/d6tstack/issues or make a pull request') Traceback (most recent call last): File "src\pymssql.pyx", line 636, in pymssql.connect File "src_mssql.pyx", line 1957, in _mssql.connect File "src_mssql.pyx", line 677, in _mssql.MSSQLConnection.init _mssql.MSSQLDriverException: Connection to the database failed for an unknown reason.

this error is familiar with pyodbc, to fix this on pyodbc i use urllib and add a param. I dont know how to pull this off with d6stack

ledikari avatar Jun 14 '19 10:06 ledikari

Hopefully you solved this by now, but adding r in front of your string like r'mssql+pymssql://someserver123\data/Comissions' might work.

DOH-Manada avatar Aug 19 '21 21:08 DOH-Manada