0

I am able to establish a connection to the database when using this code :

conn = pyodbc.connect('Driver={SQL Server Native Client 11.0}; Server=1070010-01; uid=sa; pwd=SDKJ-1111; Database = TEST_DB; Trusted_Connection=No;')

I've manually put in the user name and password . Now ,how would I write my code in order to make it take the user input and use it as credentials ? How do I set a variable for example and call it inside the function later on ?

Thank you

jarlh
  • 42,561
  • 8
  • 45
  • 63
  • 1
    Does this answer your question? [How can i pass configuration variable values into the pyodbc connect command?](https://stackoverflow.com/questions/10084969/how-can-i-pass-configuration-variable-values-into-the-pyodbc-connect-command) – jmkjaer Apr 16 '20 at 13:00

1 Answers1

0

Try this one

userName =  input("Enter DB Username: ") 
pswd =  input("Enter DB Password: ") 


conn = pyodbc.connect('Driver={SQL Server Native Client 11.0}; Server=1070010-01; uid='+ userName +'; pwd='+pswd+'; Database = TEST_DB; Trusted_Connection=No;')
Rola
  • 1,598
  • 13
  • 12