Server Error (500) Timeout after changing Database in Django MSSQL - sql-server

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.

Related

QT unable to connect to mssql server from qt application in ubuntu

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

Issue connecting Django to database

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

Problem connecting existing MSSQL server database to django project.

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.

Node.js Connection with SQL Server windows authentication

I'm trying to connect node.js to mssql in Windows Authentication mode. I installed the tedious,mssql and msnodesqlv8 modules, but I still can't figure out how to open a connection.
This is what I tried:
var sql = require('mssql');
var config = {
driver: 'msnodesqlv8',
server: 'POPPY-GI\\SQLEXPRESS',
database: 'NodinSports',
options:{
trustedConnection: true,
useUTC: true}}
sql.connect(config).then(function() {
new sql.Request().query('select * from users')
.then(function(recordset){
console.log(recordset);
}).catch(function(err) {
console.log(err);});
}).catch(function(err) {
console.log(err);});
After running I get a long error saying:
`ConnectionError`: Port for `SQLEXPRESS` not found in
`ServerName`;POPPYGI;`InstanceName;SQLEXPRESS;IsClustered`;No;Version;12.0.2000.8;;
at Connection.tedious.once.err (D:\Never Lazy\University\`AN2, SEM 2\WEB\`Projek`\node_modules\`mssql`\lib\`tedious.js:216:17`)
at Connection.g (events.js:291:16)
at emitOne (events.js:96:13)
at Connection.emit (events.js:188:7)
at D:\Never Lazy\University\AN2,SEM2\WEB\Projekt\node_modules\tedious\lib\connection.js:570:27
at D:\Never Lazy\University\AN2,SEM2\WEB\Projekt\node_modules\tedious\lib\instance-lookup.js:91:24
at Socket.onMessage (D:\Never Lazy\University\AN2,SEM2\WEB\Projekt\node_modules\tedious\lib\sender.js:140:9)
at emitTwo (events.js:106:13)
at Socket.emit (events.js:191:7)
at UDP.onMessage (dgram.js:549:8)
code: 'EINSTLOOKUP',
I would be really thankful for any help.
FIXED:
In services.msc check if the followings are enabled:
SQL Server(*server_name*) -- in my case `SQLEXPRESS`
SQL Server Browser
SQL Server Agent(*server_name*) -- if you are using `SQLEXPRESS` this doesn't need to run
In SQL Server Configuration Manager -> Protocols for server_name: enable TCP/IP.
To make sure everything will be fine, check the port the server is using (SQL Server Configuration Manager -> SQL Native Client Configuration -> Client Protocols -> double click on TCP/IP -> Default Port ) , and add the port: *your_port* to the code in var config = { ... }.
Lastly, change var sql = require('mssql'); to var sql = require("mssql/msnodesqlv8");
Install the following modules:
"dependencies": {
"msnodesqlv8": "^0.4.14",
"mssql": "^4.1.0"
}
My node version: v8.1.4
const sql = require("mssql/msnodesqlv8");
const main = async () => {
const pool = new sql.ConnectionPool({
server: "myservername",
database: "mydbname",
options: {
trustedConnection: true
}
});
await pool.connect();
const request = new sql.Request(pool);
const query = `SELECT [FirstName]
,[LastName]
,[Email]
FROM [Dev].[Users]`;
const result = await request.query(query);
console.dir(result);
};
main();
(You can do it without async or older versions: https://stackoverflow.com/a/40406998/639575)
The solution given by beatoss works for windows but not for Linux/mac. The msnodesqlv8 driver only works for Windows. For Linux/mac environment, try odbc instead.
It may be too late to answer, but this recently happened with me and it drove me crazy!!! I was trying to connect my db to express and I was working with windows authentication mode. For two long days I kept googling and refreshing until I got this article: https://www.liquidweb.com/kb/troubleshooting-microsoft-sql-server-error-18456-login-failed-user/
So in a nutshell;
First I installed the msnodesqlv8 driver for windows authentication, then in the my server on ssms, I right clicked on my server then in properties and then security, I enabled sql server and windows authentication mode, then in the object explorer, clicked on the plus next to the server, then security, then logins. There I saw sa with a cross next to it. In it's properties, I changed my password to something easier to remember (optional), then in the status, set the login to enable. PHEW!
Now my config code: <br / >
const config = {
user: 'sa',
password: '123',
driver: "msnodesqlv8",
server: 'UZAIR-S_PC\\SQLEXPRESS',
database: 'LearningExpressJS',
options: {
trustedconnection: true,
enableArithAbort : true,
trustServerCertificate: true,
instancename : 'SQLEXPRESS'
},
port: 58018
}
This works finally !!!!!!!!!!!!!!!

unixODBC works but Apache will not connect

I am trying to setup apache to connect to a Microsoft SQL server for authentication. This is not ideal but this legacy system has the credentials in MSSQL and that can not change. I have unixODBC setup and working
**odbcinst.ini**
[SQL Server Native Client 11.0]
Description = Microsoft SQL Server ODBC Driver V1.0 for Linux
Driver = /opt/microsoft/sqlncli/lib64/libsqlncli-11.0.so.1790.0
Threading = 1
UsageCount = 1
**odbc.ini**
[mssql]
Driver = SQL Server Native Client 11.0
Server = 192.168.250.200
Database = DBName
When I connect using isql I am able to query the database without issue
isql mssql username password
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
In apache I have configured the following
DBDriver odbc
DBDParams "datasource=mssql,user=username;pass=password"
DBDMin 1
DBDKeep 2
DBDMax 10
DBDExptime 300
When I start httpd I get this in the error log
[Thu Dec 10 09:10:35 2015] [dbd_odbc] SQLDriverConnect returned SQL_ERROR (-1) at dbd/apr_dbd_odbc.c:1146 [unixODBC][Microsoft][SQL Server Native Client 11.0]Login timeout expired HYT00 [unixODBC][Microsoft][SQL Server Native Client 11.0]TCP Provider: Error code 0xD 08001 [unixODBC][Microsoft][SQL Server Native Client 11.0]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 confi 08001
[Thu Dec 10 09:10:35.633986 2015] [dbd:error] [pid 15481] (20014)Internal error: AH00629: Can't connect to odbc: [dbd_odbc] SQLDriverConnect returned SQL_ERROR (-1) at dbd/apr_dbd_odbc.c:1146 [unixODBC][Microsoft][SQL Server Native Client 11.0]Login timeout expired HYT00 [unixODBC][Microsoft][SQL Server Native Client 11.0]TCP Provider: Error code 0xD 08001 [unixODBC][Microsoft][SQL Server Native Client 11.0]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 confi 08001
[Thu Dec 10 09:10:35.634054 2015] [dbd:error] [pid 15481] (20014)Internal error: AH00633: failed to initialise
[Thu Dec 10 09:10:35.634200 2015] [dbd:crit] [pid 15481] (20014)Internal error: AH00636: child init failed!
SELinux was blocking the connection from Apache.

Resources