python connectorx mssql issues with databases with spaces in the name

21 Views Asked by At

I have four databases located on the same SQL instance.

3/4 of the databases located on this instance have underscores "_" separating every word of their name, and I can access these databases directly via URI

We store a local copy of some of our data in the 4th database we call "db backups".

from using {} to [], I cannot seem to find a way to directly access this database. As a workaround, I can access one of the other databases and just include the database I can't connect to directly in the FROM clause of the SQL statement.

I'm currently using connectorx via polars for the speed of access, below is a sample of how I'm writing these queries in python. Note that the brackets are not there, just using this to demonstrate the format

uri_string = "mssql://[Username]:[Password]@[IP Address]:[port]/[database_name]

query201 = """
SELECT *
FROM [database_name].[dbo].[Table]
"""

df_201 = pl.read_database_uri(query=query201, uri=uri_string)

and for any [database_name] separated by underscores, this works fine. but for "db backups", the query times out.

Any suggestions on how to work with databases with a space in the name?

0

There are 0 best solutions below