pykara commited on
Commit
c6dc8f1
·
verified ·
1 Parent(s): 9064afa

Update verification.py

Browse files
Files changed (1) hide show
  1. verification.py +24 -17
verification.py CHANGED
@@ -106,33 +106,40 @@ app.config["COHERE_API_KEY"] = os.getenv("COHERE_API_KEY", "")
106
  # DB_SERVER = "pykara-sqlserver.cb60o04yk948.ap-south-1.rds.amazonaws.com,1433"
107
  # DB_DATABASE = "AuthenticationDB1"
108
 
109
- DB_SERVER = os.getenv("DB_SERVER", "localhost")
110
  DB_DATABASE = os.getenv("DB_DATABASE", "AuthenticationDB1")
111
  DB_DRIVER = os.getenv("DB_DRIVER", "ODBC Driver 17 for SQL Server") # 17 in your image
112
 
113
- # if DB_SERVER.lower().startswith("localhost") or "\\" in DB_SERVER:
114
- # CONN_STR = f"DRIVER={{SQL Server}};SERVER={DB_SERVER};DATABASE={DB_DATABASE};Trusted_Connection=yes"
115
- # else:
116
- # CONN_STR = (
117
- # "DRIVER={ODBC Driver 17 for SQL Server};"
118
- # f"SERVER={DB_SERVER};DATABASE={DB_DATABASE};"
119
- # f"UID={os.getenv('DB_USER')};PWD={os.getenv('DB_PASSWORD')};"
120
- # "Encrypt=yes;TrustServerCertificate=yes"
121
- # )
122
-
123
- # Build connection string
124
- if DB_SERVER.lower().startswith("localhost") or "\\" in DB_SERVER:
125
- # Windows local named instance / integrated auth
126
- CONN_STR = f"DRIVER={{SQL Server}};SERVER={DB_SERVER};DATABASE={DB_DATABASE};Trusted_Connection=yes"
 
 
 
 
127
  else:
128
- # SQL auth with explicit driver
129
  CONN_STR = (
130
  f"DRIVER={{{DB_DRIVER}}};"
131
  f"SERVER={DB_SERVER};DATABASE={DB_DATABASE};"
132
  f"UID={os.getenv('DB_USER')};PWD={os.getenv('DB_PASSWORD')};"
133
- "Encrypt=yes;TrustServerCertificate=yes"
134
  )
135
 
 
 
 
136
  # def get_db_connection():
137
  # """Create a short-timeout connection. Fail clearly if secrets are missing."""
138
  # if "Trusted_Connection=yes" not in CONN_STR:
 
106
  # DB_SERVER = "pykara-sqlserver.cb60o04yk948.ap-south-1.rds.amazonaws.com,1433"
107
  # DB_DATABASE = "AuthenticationDB1"
108
 
109
+ DB_SERVER = os.getenv("DB_SERVER", r"(localdb)\MSSQLLocalDB")
110
  DB_DATABASE = os.getenv("DB_DATABASE", "AuthenticationDB1")
111
  DB_DRIVER = os.getenv("DB_DRIVER", "ODBC Driver 17 for SQL Server") # 17 in your image
112
 
113
+
114
+ # Build connection string (FIXED)
115
+ is_local = (
116
+ DB_SERVER.lower().startswith("localhost")
117
+ or DB_SERVER.startswith(".")
118
+ or DB_SERVER.lower().startswith("(localdb)")
119
+ or "\\" in DB_SERVER
120
+ )
121
+
122
+ if is_local:
123
+ # Windows local / LocalDB using modern ODBC driver
124
+ CONN_STR = (
125
+ f"DRIVER={{{DB_DRIVER}}};"
126
+ f"SERVER={DB_SERVER};"
127
+ f"DATABASE={DB_DATABASE};"
128
+ "Trusted_Connection=yes;"
129
+ "TrustServerCertificate=yes;"
130
+ )
131
  else:
132
+ # Remote SQL auth
133
  CONN_STR = (
134
  f"DRIVER={{{DB_DRIVER}}};"
135
  f"SERVER={DB_SERVER};DATABASE={DB_DATABASE};"
136
  f"UID={os.getenv('DB_USER')};PWD={os.getenv('DB_PASSWORD')};"
137
+ "Encrypt=yes;TrustServerCertificate=yes;"
138
  )
139
 
140
+
141
+
142
+
143
  # def get_db_connection():
144
  # """Create a short-timeout connection. Fail clearly if secrets are missing."""
145
  # if "Trusted_Connection=yes" not in CONN_STR: