Hi I'm trying to use Python 3 with MS SQL Server Express 2008 R2.
I'm using Visual Studio as an IDE, and trying to use pymssql.
In my code I did the following:
conn = _mssql.connect(server='GAL-PC\SQLEXPRESS', user='gal', password='pass', \
database='tempdb')
I've set the user name and the password using MS SQL Server Management Studio.
All I'm getting is this error:
_mssql.MSSQLDriverException: Connection to the database failed for an unknown reason.
Why is my code giving me an error?
Related
I am trying to connect to a database, from a Windows 10, that is on another pc in the same local network using the pyodbc module. The external pc is a Windows Server 2003 and it has a database Microsoft SQL Server 2005. I am not sure how the connection string has to be, I have tried with the following code:
import pyodbc
DRIVER = "{ODBC Driver 11 for SQL Server}" # supports SQL Server 2005 through 2014
SERVER = "192.168.100.101" # the ip of the windows server 2003
PORT = "1433" # I am not sure if this parameter is needed
DATABASE = "database_name" # name of the database
USER = "user"
PASS = "psw"
string_connection = f"DRIVER={DRIVER};SERVER={SERVER};PORT={PORT};DATABASE={DATABASE};UID={USER};PWD={PASS}"
cnxn = pyodbc.connect(string_connection)
cursor = cnxn.cursor()
cursor.close()
cnxn.close()
But when I run the code above I get the following error:
InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
Data source name not found and no default driver specified
This error message indicates the driver specified in the connection string is not installed on the client machine. Run odbcad32.exe on the Win10 machine and click the drivers tab to view the list of installed ODBC drivers.
To remediate, you can either change the connection string to use an already installed SQL Server ODBC driver, or install the ODBC Driver 11 for SQL Server from here.
Be aware that Windows Server 2003 and SQL Server 2005 have been out of support for several years. The oldest support Windows server version is 2012 and SQL 2012 is the oldest SQL version as of this writing. I suggest you migrate to newer versions.
I am trying to connect to my database on MS SQL Server 2016 using pyodbc via the below python script from my laptop (on Windows 10) and planning to have the code deployed in a Linux RHEL 6.4 server.
conn=pyodbc.connect('Driver={SQL Server};'
'Server=DB_Instance;'
'Database=DB_Name;'
'UID=user_name;'
'PWD=password;'
'Trusted_Connection=no;');
At my laptop, SQL Server (version: 10.00.17763.01) and SQL Server Native Client 11.0 (version: 2011.110.7493.04) are already available.
While executing the python script from my laptop, I am getting the below error message.
pyodbc.operationalError: ('08001', '[08001] [Microsoft] [ODBC SQL Server Driver][DBNETLIB]SSL Security error (18) (SQLDriverConnect); [08001] [Microsoft] [ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (SECDoClientHandshake()). (772)')
As per the organization standard, TLS 1.0 is disabled on the windows server where the SQL Server is installed in the network. Since I am accessing the database via python script, we cannot temporarily enable TLS 1.0. I am looking for a direction. Any help is greatly appreciated!!
Gord Thompson pointed Guna in the right direction in the comments:
Can you try using ODBC Driver 17 for SQL Server and see if that works for you?
– Gord Thompson
Guna said that this worked:
I was facing different set of errors. While adding the port number in addition to the server name, the problem got resolved. The ODBC Driver name also needs to be updated. conn=pyodbc.connect('Driver={ODBC Driver 17 for SQL Server};' 'Server=DB_Instance,port;' 'Database=DB_Name;' 'UID=user_name;' 'PWD=password;' 'Trusted_Connection=no;');
– Guna
Posting this as a community Wiki just so that any searchers can see quickly that it was answered.
PROBLEM: -
When trying to perform password change for MSSQL server, you get the following error message:-SSL Security error
SOLUTION: -
It's likely an issue with the version of the SQL Native Client driver being used to establish the connection.
Please Download & install "ODBC Driver 13 for SQL Server" on the CPM servers.
https://www.microsoft.com/en-us/download/confirmation.aspx?id=50420
Download 32 bit driver : x86\msodbcsql.msi
Install as usual
Edit MSSQL Platforms to change the connection command from
Driver={SQL Server};Server=%ADDRESS%;Database=%DATABASE%;Uid=%USER%;Pwd=%LOGONPASSWORD%;
to
Driver={ODBC Driver 13 for SQL Server};Server=%ADDRESS%;Database=%DATABASE%;Uid=%USER%;Pwd=%LOGONPASSWORD%;
Restart the CPM service to pick up the platform changes & retest
I am using pyodbc module to connect to MS access DB from python. However, the only driver available when i run the following command is SQL Server.
"pyodbc.drivers()"
I have installed the Visual Studio 2017 Community. I installed (or so I think) the Oracle 32 and 64 bit client and I managed to connect with the Visual Studio to an Oracle database from Tools -> Database Connection -> Oracle.
Now, I have a code in Python that uses the cx_Oracle library to connect to an Oracle database. When I execute it, the connection breaks and I check some blogs, it tells me that it is due to incompatibility of the Oracle client. I installed the Oracle ODAC2018 for Visual Studio.
Now, I do ALT + I to open the interactive console with the following lines (which are the same as I use to connect from the code)
import cx_Oracle
db_pass_str = "xxx"
db_usr_str = "yyy"
db_str = "database"
db = cx_Oracle.connect (db_usr_str + "/" + db_pass_str + "#" + db_str)
And I manage to make the connection to it. I am using Python 3.7 of 64 bit, my Windows machine is of 64 bit and the database is in a unix server to which I connect without any novelty by any means (sqlplus, sqldeveloper).
A similar code is the one that handles the Python code of the program that I am executing. I no longer see the way to connect. From the Pycharm achievement that the program is executed but by Visual Studio no.
Could someone help me with that?
I am trying to connect to MS Sql Server using python and sqlalchemy, with trusted connection / active directory / kerberos authentication. I was able to connect before, but now I am getting this error:
Error: ('HY000', u'[HY000] [Microsoft][ODBC Driver 13 for SQL Server]SSPI Provider: Ticket expired (negative cache) (851968) (SQLDriverConnect)')
I was able to resolve this by running kinit in terminal with no options.