How to connect pyqt5 desktop application to an sql server management studio database on a different computer.
-
wrote on 8 Aug 2023, 12:00 last edited by LT-K101 8 Aug 2023, 12:06
Am trying to connect a python script on computer A to Microsoft server management studio database on computer B. I did the following and am getting the error message below. Please I need help this is my first time implementing this and am struggling with this.
import pyodbc # Connection parameters server = '192.178.45.10' database = 'test' username = 'DESKTOP-SE75VSF\User-PC' password = 'pass' # Create a connection string connection_string = f'DRIVER=SQL Server;SERVER={server};DATABASE={database};UID={username};PWD={password}' try: # Establish connection connection = pyodbc.connect(connection_string) cursor = connection.cursor() # Close cursor and connection cursor.close() connection.close() except pyodbc.Error as e: print('Error:', e)
Error saying I get error pyodbc. InterfaceError: ('IM002', '[IM002] [MICROSOFT] [ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQL DriverConnect)')
-
Am trying to connect a python script on computer A to Microsoft server management studio database on computer B. I did the following and am getting the error message below. Please I need help this is my first time implementing this and am struggling with this.
import pyodbc # Connection parameters server = '192.178.45.10' database = 'test' username = 'DESKTOP-SE75VSF\User-PC' password = 'pass' # Create a connection string connection_string = f'DRIVER=SQL Server;SERVER={server};DATABASE={database};UID={username};PWD={password}' try: # Establish connection connection = pyodbc.connect(connection_string) cursor = connection.cursor() # Close cursor and connection cursor.close() connection.close() except pyodbc.Error as e: print('Error:', e)
Error saying I get error pyodbc. InterfaceError: ('IM002', '[IM002] [MICROSOFT] [ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQL DriverConnect)')
wrote on 8 Aug 2023, 12:07 last edited by JonB 8 Aug 2023, 12:18@LT-K101 said in How to connect pyqt5 desktop application to an sql server management studio database on a different computer.:
connection_string = f'DRIVER=SQL Server;SERVER={server};DATABASE={database};UID={username};PWD={password}'
I trust this is not actually the literal string you pass, is it? [OIC, you have defined the Python variables for interpolation, got it.]
Your code is 100% Python with its internal database connection library. You do not use Qt or Qt's SQL database library here, so your question would best be addressed to a Python forum rather than a Qt one.
P.S.
DRIVER=SQL Server
Are you sure this correct? Where did you copy this from? You sure it wasn't supposed to be
DRIVER={SQL Server}
Even then I'm not sure whether
SQL Server
isn't a very old name to use for the driver?Otherwise various suggestions in, say, https://stackoverflow.com/questions/46045834/pyodbc-data-source-name-not-found-and-no-default-driver-specified or other hits by Googling the error message.
Finally, just to make sure: the MS SQL Server you want to connect to on the server is running a default instance of MSSQL Server, right? Not a named instance?
1/2