Connecting to MS SQL Database using windows Authentication using JAYDEBEAPI python script

1.5k views Asked by At

I am trying to connect to SQL Server using jaydebeapi in python but every time I am getting same error:

java.sql.SQLException: java.sql.SQLException: I/O Error: DB server closed connection.

I know this is an old question but with the same code I am able to connect to other SQL Server databases but now when I try to connect one other SQL Server then T am getting mentioned error. Can anyone tell me what could be the reason. Here is my code:

import jaydebeapi

jarName = "jtds-1.3.1-dist/jtds-1.3.1.jar"

driver = "net.sourceforge.jtds.jdbc.Driver"

server = "server"

db_name = "dbname"

host = "host"

jdbcString = """jdbc:jtds:sqlserver://{0};databaseName={1};integratedSecurity=true;useNTLMv2=true;domain={2}""".format(server,db_name,host)

print(jdbcString)

sql_db_conn = jaydebeapi.connect(driver, jdbcString, ['username', 'password'], jarName)

if sql_db_conn:
  print(sql_db_conn)
else:
  print("not connected")
0

There are 0 answers