0

I am new to Python (3.8), and we are migrating old programs developed in Visual FoxPro. We must connect to an Advantage Database Server 9.1 database through ODBC. But using the same connection string that works correctly in Fox, using pypyodbc, I can't establish the connection. The code is the following:

import pypyodbc

str_sql = """Driver={Advantage StreamlineSQL ODBC};SERVER=local;
DataDirectory=D:\ps-datos\UNEE.add;
DATABASE=UNIRE;UID=AdsSys;PWD=/-789;ServerTypes=2;"""

conn = pypyodbc.connect(str_sql)

The error that throws to me when trying the 'connect', is: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 77-78: truncated \UXXXXXXXX escape I understand that putting the path of the file 'add' (DataDirectory = D:\ps-data\UNEE.add), it takes the character "\" as an escape sequence. I have tried to fix it, but it has led to new errors. Can anyone tell me how to correctly write that connection string?

  • Hey, in Python, the backslash char has to escaped. As you can write "\n" for a new line or "\r" for carriage return. So your connection string needs every single "\" replaced with a double backslash. – DerHamm Jul 24 '20 at 07:11
  • Could you resolve the error? – DerHamm Jul 30 '20 at 12:18

0 Answers0