#๐Ÿ”’ Help pls

5 messages ยท Page 1 of 1 (latest)

slate anvil
#

Hi guys,

Im doing a project for work and I have a function to connect to our Azure SQL Server database. I am using the right connection string based on the Azure which is Driver={ODBC Driver 18 for SQL Server};Server=;Database=;Uid={your_user_name};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;Authentication=ActiveDirectoryIntegrated.

The weird thing is that this connection worked for almost 2 months now until yesterday where I started getting an error message.

The error message is shown below:

Error connecting to the database: ('HY000', '[HY000] [Microsoft][ODBC Driver 18 for SQL Server]An unknown error has occurred. Detailed error information is not available. (0) (SQLDriverConnect); [HY000] [Microsoft][ODBC Driver 18 for SQL Server]Invalid connection string attribute (0); [HY000] [Microsoft][ODBC Driver 18 for SQL Server]Invalid connection string attribute (0); [HY000] [Microsoft][ODBC Driver 18 for SQL Server]An unknown error has occurred. Detailed error information is not available. (0)')

I checked with our infrastructure and apparently nothing is blocking it. I could connect using SSMS/Azure Studio.

Can someone please review my code and tell me im not going crazy here cause I cant see anything wrong with it

Code snippet:

    server = '*'
    database = '*'
    username = '*'
    driver = 'ODBC Driver 18 for SQL Server'

    # Construct connection string
    conn_str = (f"""DRIVER={{{driver}}};
                server={server};
                database={database};
                Uid={username};
                Encrypt=yes;
                TrustServerCertificate=no;
                Connection Timeout=30;
                Authentication=ActiveDirectoryIntegrated;
                """)

    connection = pyodbc.connect(conn_str)

    return connection

connection = connect_to_db()
cursor = connection.cursor()```
valid sandBOT
#

Hey @slate anvil!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
valid sandBOT
#

@slate anvil

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

valid sandBOT
#

@slate anvil

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.