I'm currently using python 3.6 and django 2.1.11. I have a database I'm trying to connect to to make migrations.
Currently my settings looks like:
'Project': {
'ENGINE': "sql_server.pyodbc",
'HOST': os.environ.get("DJANGO_DB_SERVER"),
'USER': os.environ.get("DJANGO_DB_UID"),
'PASSWORD': os.environ.get("DJANGO_DB_PWD"),
'NAME': "Project",
'CONN_MAX_AGE' : 600,
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
}
},
I have the settings set in a PowerShell script that I run to set up the env variables. When I try and make migrations I get the following error:
django.db.utils.InterfaceError: ('28000', "[28000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'mssql_appuser'. (18456) (SQLDriverConnect); [28000] [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute (0); [28000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'mssql_appuser'. (18456); [28000] [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute (0)")
I went into pyodc base file and added a print statement to see what my connection string looked like:
DRIVER=ODBC Driver 17 for SQL Server;SERVER=db_name;UID=test;PWD=test;DATABASE=Project;MARS_Connection=yes
Not sure whats wrong here. If I attempt to add {} around the driver in the ps1 file the connection comes up like this:
DRIVER={{ODBC Driver 17 for SQL Server}}};SERVERNAME=db_name;UID=test;PWD=test;DATABASE=Project
which seems incorrect
Any advice on how to fix this would be appreciated
Related
Unable to connect to mssql server from qt application in ubuntu 20.04
Sql server located in windows 7
The connection is definitely present, because it was possible to connect through DDbeaver.
Can anyone help me in this situation?
Code:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
db.setConnectOptions();
QString serverName = "566***";
QString ipName = "tcp:192.168.144.101,1433";
QString dbName = "St***";
QString connectionString = QString("DRIVER={ODBC Driver 18 for SQL Server};Server=%1;Database=%2;").arg(ipName).arg(dbName);
db.setDatabaseName(connectionString);
db.setUserName("sa");
db.setPassword("top123TOP");
if (db.open())
{
qDebug() << "Correct connection";
}
else
{
QString error = db.lastError().text();
qDebug() << error;
}
otuput is:
"[Microsoft][ODBC Driver 18 for SQL Server]TCP Provider: Error code 0x2746 [Microsoft][ODBC Driver 18 for SQL Server]Client unable to establish connection QODBC3: Unable to connect"
odbcinst.ini
[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1
the following solution helped:
from:https://github.com/microsoft/msphpsql/issues/1112
This was helpful.
Ubuntu 20.04 PHP 7.4 using the 19.10 drivers for sqlsrv
We have a real old SQL server out there . The SQL Server show's version 10.50.2550.0, i think it's SQL Server 2008 R2. I had to use TLSv1 to connect to the server. I also had to do a "systemctl restart apache2" to get it to take affect. TLSv1.1 did not work with my MSSQL server version.
Error message: Connection failed: SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]SSL Provider: [error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol]Database Connection Error
edit: /etc/ssl/openssl.cnf
1st line in the file added
openssl_conf = default_conf
End of file added
[default_conf]
ssl_conf = ssl_sect
[ssl_sect]
system_default = system_default_sect
[system_default_sect]
MinProtocol = TLSv1
CipherString = DEFAULT#SECLEVEL=1
Not 100% sure why i had to restart apache2 for it to take effect, but I had to.
systemctl restart apache2
reloaded the page and it works
I have pulled a docker image that runs an MS SQL from docker hub:
docker pull mcr.microsoft.com/mssql/server:2017-latest
docker run --name some-db -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=Aamerge1234 -e MSSQL_PID=Developer -d -p 1433:1433 mcr.microsoft.com/mssql/server:2017-latest
The container runs fine, I added a strong password as required.
This is the python code I am using to connect with the database using pyodbc:
import pyodbc
server = 'localhost:1433'
# database = ''
username = 'sa'
password = 'Aamerge1234'
conn = pyodbc.connect('DRIVER={SQL Server Native Client 11.0};SERVER='+server+';UID='+username+';PWD='+ password)
I have omitted the variable database because mssql creates several.
I tried using the following ODBC drivers:
ODBC Driver 17 for SQL Server
SQL Server
However, it always returns error:
OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. (53) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0); [08001] [Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (53)')
I've always accessed my University's database using pyodbc in my own machine. However, when I try to use the same code (below) in a Virtual Machine (VMware) I receive an error (translated from Portuguese to English):
import pyodbc
server = 'beirute-01'
database = 'RAIS'
port= '1433'
username = 'gabrielcp2'
password = '*****'
driver= '{ODBC Driver 17 for SQL Server}'
cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT='+port+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
-------------------------------------------------- -------------------------
OperationalError Traceback (most recent call last)
C:\Users\GABRIE~1\AppData\Local\Temp/ipykernel_2064/1387256718.py in <module>
11 driver= 'ODBC Driver 17 for SQL Server'
12
---> 13 cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT='+port+';DATABASE='+database+';UID='+username+';PWD=' + password)
14
15 cursor = cnxn.cursor()
OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Timeout Error [258]. (258) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Logon timed out (0); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute (0); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Cannot complete login process due to pre-logon response delay (258)')
How could I fix it?
So after finishing my Django Project everything works fine on the test database server with following settings:
DATABASES = {
'default': {
'ENGINE':'sql_server.pyodbc',
'NAME':'xxx',
'USER':'xxx',
'PASSWORD':'xxx',
'HOST':'192.168.10.40',
'OPTIONS': {
'driver': 'ODBC Driver 13 for SQL Server',
},
},
'200000': {
'ENGINE':'sql_server.pyodbc',
'NAME':'xxx',
'USER':'xxx',
'PASSWORD':'xxx',
'HOST':'192.168.10.40',
'OPTIONS': {
'driver': 'ODBC Driver 13 for SQL Server',
},
},
}
but after trying to change it to the new database server like:
DATABASES = {
'default': {
'ENGINE':'sql_server.pyodbc',
'NAME':'xxx',
'USER':'xxx',
'PASSWORD':'xxx',
'HOST':'192.168.10.36/ATS',
'OPTIONS': {
'driver': 'ODBC Driver 13 for SQL Server',
},
},
'200000': {
'ENGINE':'sql_server.pyodbc',
'NAME':'xxx',
'USER':'xxx',
'PASSWORD':'xxx',
'HOST':'192.168.10.36\ATS',
'OPTIONS': {
'driver': 'ODBC Driver 13 for SQL Server',
},
},
}
i get a server error 500 after like 2minutes when i change the database server back to the old one it works again what problems can cause this error? can it be that i got an instance on the server and the /ATS is causing the problem?
After some research and setting debug to true in django i get the following error msg:
OperationalError at / ('HYT00', '[HYT00] [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
In the Apache error log there is following error:
[Tue Feb 12 08:02:24.905988 2019] [ssl:warn] [pid 12571:tid 139890139985088] AH01916: Init: (127.0.1.1:443) You configured HTTP(80) on the standard HTTPS(443) port! [Tue Feb 12 08:02:24.918022 2019] [ssl:warn] [pid 12572:tid 139890139985088] AH01916: Init: (127.0.1.1:443) You configured HTTP(80) on the standard HTTPS(443) port!
When i run the django app on visual studio it works fine with the new sql server settings. only after deploying it to apache with the new sql server settings i cant establish a connection.
I need to connect a django project to an excisting MS SQL-Server database however I'm getting an error I don't understand:
django.db.utils.InterfaceError: ('IM002', '[IM002] [Microsoft][Driver Manager ODBC] Nome origine dati non trovato e driver predefinito non specificato. (0) (SQLDriverConnect)')
English translation I found after googling this:
django.db.utils.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
I have no idea what this means, however, I found this question which showed how to setup the DATABASES values in django. Currently my DATABASES looks like this:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': '<DATABASE NAME>',
'HOST': '<PCNAME>\SQLEXPRESS',
'USER': '<USERNAME>',
'PASSWORD': '<PASSWORD>',
'PORT': '',
'OPTIONS': {
'driver': 'SQL Native Client',
'dsn': 'dsn_entry',
'host_is_server': True
}
}
}
the server is on localhost and I'm using windows 7, django 2.1, python 3.7 and SQL Server 2014 Express
What is this error and what am I doing wrong?
A DSN is a pre-defined hostname and driver (and potentially other things) that are defined in a configuration file like ~/.odbc.ini. change the driver inside the odbc.ini file.