Tiger Wang
Tiger Wang

Reputation: 1

ImportError when trying to connect Azure SQL database in LangChain

I have been following this guide to try to query GPT3.5 on my SQL database, hosted on Azure. https://gist.github.com/anderl80/5a593cbfc6d44283864917743557d8da

I am running into an import error on these two lines of code:

connection_string = f"mssql+pymssql://{database_user}:{database_password}@{database_server}.database.windows.net:1433/{database_db}"

db = SQLDatabase.from_uri(connection_string)

Error

Not sure how to move on from here. Looking for any guidance. Thanks!

Upvotes: 0

Views: 245

Answers (1)

Sampath
Sampath

Reputation: 3591

  • Used This reference To Connect to SQL using pymssql Python driver for SQL Server.

  • The error you're encountering seems to be related to the pymssql library. Used python --version Python 3.10.9. Install pip install pymssql

import  pymssql
server = 'sampath234.database.windows.net'
username = 'sampath125'
password = 'Sa@80mpath'
database = 'sampath'
try:
conn = pymssql.connect(server=server,  user=username,  password=password,  database=database)
print("Connected to the database successfully!")
conn.close()
except  pymssql.Error as  err:
print("Error:",  err)

enter image description here

Upvotes: 0

Related Questions