I am trying to drop a view from my synpase Notebook using a connection to a Serverless SQL Pool. I followed the instructions from this post: Access our built-in serverless SQL pool from our notebook and successfully made the connection. I can query my tables without any issues. However, when I try to drop a view I get this error: An error occurred while calling o4311.jdbc. The code snippet I used below:
%%pyspark
server = 'REDACTED'
Port = 1433
Database = "REDACTED"
jdbcUrl = f"jdbc:sqlserver://{server}:{Port};databaseName={Database};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30"
token=TokenLibrary.getConnectionString("LinkTest")
query = "DROP VIEW dbo.TransformationTest"
conn_Prop = {
"driver" : "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"accessToken" : token
}
df = spark.read.jdbc(url=jdbcUrl, table=query, properties=conn_Prop)
display(df)
I was advised to use pyodbc for DDL commands, but I encountered an error with TokenLibrary saying that it is unrecognized, even though it was recognized before using pyodbc. This is The code snipet used:
%%pyspark
%pip install pyodbc
import pyodbc
CONNECTION CODE
token=TokenLibrary.getConnectionString("LinkTest")
conn_str = f'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={server},{Port};DATABASE={Database};Authentication=ActiveDirectoryMsi'
# Establish a connection
conn = pyodbc.connect(conn_str)
# Create a cursor from the connection
cursor = conn.cursor()
# Define and execute the DROP TABLE query
drop_query = "DROP VIEW dbo.TransformationTest"
cursor.execute(drop_query)
# Commit the transaction
conn.commit()
# Close the connection
cursor.close()
conn.close()
This is the error I get: NameError: name ‘TokenLibrary’ is not defined
I would appreciate any guidance on how to successfully drop the view or any insights into resolving the TokenLibrary error with pyodbc.