Django connect to MSSQL - django

Hi I am trying to connect from django to mssql server. I installed
1 : pip install django-mssql
2 : pip install pywin32
after that i changed the database inside setting.py =>
DATABASES = {
'default': {
'NAME': 'TMSWEB',
'ENGINE': 'sql_server.pyodbc',
'HOST': '192.168.72.1\MSSQLSERVER5',
'USER': 'sa',
'PASSWORD': 'pwd',
'OPTIONS': {
'driver': 'ODBC Driver 13 for SQL Server',
}
}
}
and then i check like that=>
2: python manage.py makemigrations
django.db.utils.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC
Driver Manager] Data source name not found and no default driver
specified (0) (SQLDriverConnect)')
What i am still need to do? Please help me.
my django version : 2.1.11

This is because of I don't have ODBC Driver 13 for SQL Server. I download from ODBC Driver 13 for sql server and installed. Its fixed. Thanks.

Related

Django, using oracledb error msg that I need Oracle 19

I am confused since the documentation for oracledb clearly states that everything past 12.1 should work fine. Could someone please explain to me where I went wrong? The error was created when I tried to create migrations.
The document I am referencing is: oracledb docs
Here is the error:
django.db.utils.NotSupportedError: Oracle 19 or later is required (found 12.2.0.1.0).
And here is my databases string in my settings.py:
from pathlib import Path
import sys
import oracledb
oracledb.version = "8.3.0"
sys.modules["cx_Oracle"] = oracledb
#the above line was added because of error (django.core.exceptions.ImproperlyConfigured: Error
#loading cx_Oracle module: No module named 'cx_Oracle')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': (
'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server123)(PORT=1521))'
'(CONNECT_DATA=(SERVICE_NAME=server.domain.com)))'
),
'USER': 'user123',
'PASSWORD': 'password',
'OPTIONS': {
'threaded': True,
},
}
}
It's a Django thing. From docs.djangoproject.com/en/4.1/ref/databases/#oracle-notes:
"Django supports Oracle Database Server versions 19c and higher."
Also see the Django 4.0 release notes
"Dropped support for Oracle 12.2 and 18c".
Try an older version of Django if you can't upgrade the DB

Django Connection not working properly with Azure Active Directory

I'm trying to put my application out in production. It was fully working when I was working locally, and it also worked when I did it in a test database in azure.
The problem is that now, when I want to use the actual production database, it is sending me errors.
I'm pretty sure that I have all the settings correct, but I think this is something I have to change inside my Azure settings, but I can't find out why.
This is my connection:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'Reconciliation',
'USER': 'mymail#mycompany.net',
'PASSWORD': 'pa$$words$$$.',
'HOST': 'mycompany.database.windows.net',
'PORT': '',
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
},
},
}
This is the error I'm getting:
[HY000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot open server "myserver" requested by the login. The login failed. (40532); [HY000] [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute (0)')
Should I be changing some settings inside Azure for it to work?
The default was correct. I had to add this so it worked:
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
"extra_params": 'Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;Authentication=ActiveDirectoryPassword',
},
The options will depend on the service you are using. I went into the azure portal and there they specified which where this extra parameters I needed to add.

while connecting to MicrosoftSQL server using Django facing django.db.utils.OperationalError:

drivers available with me
**python shell**
'''In [2]: pyodbc.drivers()'''
**Output:**
**Out[2]: ['SQL Server']**
code in settings.py django:
**Settings.py in django**
'''# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'dbname',
'HOST': 'ansqlserver.database.windows.net',
'USER': 'test',
'PASSWORD': 'Password',
'OPTIONS': {
'driver': 'SQL Server',
}
}'''
**ERROR:**
**Trying to connect to MicrsoftSQL server facing below error**
File "C:\Local\Programs\Python\Python37\lib\site-packages\sql_server\pyodbc\base.py", line 314,
in get_new_connectiontimeout=timeout)
django.db.utils.OperationalError: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver]Neither DSNnor SERVER keyword supplied (0) (SQLDriverConnect); [08001] [Microsoft][ODBC SQL Server Driver]Invalid connection string attribute (0)')
Check if your database host "ansqlserver.database.windows.net" has permission to allow application server to connect.
Initally I have only one driver: 'SQL Server'
later I installed different drivers
Just enter command and see the drivers in your machine
'''pyodbc.drivers()'''
Output: ['SQL Server',
'ODBC Driver 17 for SQL Server',
'ODBC Driver 13 for SQL Server']
after that I am able to connect to MicrosoftSQL DB without any issues

How do I get Jython-Django to work with Postgresql JDBC

I have tried to setup an instance of Django on Jython using Postgresql. I can't get Django to talk to Postgresql. Can someone help me figure out what is wrong?**
So far, I have the following system installed for development:
Windows 7
JDK7 (x86)
Jython Version 2.7b2
Django-1.6.5
django-jython 1.7.0b2(Database backends and management commands, for development underDjango/Jython)
postgresql-9.3.5-1-windows-x64.exe
Eclipse-PyDev
I was able to run the server and database, but now I am having issues with configuring Django to work with the Postgresql database.
I followed the configuration steps here:
https://pythonhosted.org/django-jython/database-backends.html#postgresql
My settings.py file has the following:
DATABASES = {
'default': {
'ENGINE': 'doj.db.backends.postgresql',
'NAME': 'gate',
'USER': 'gate',
'PASSWORD': 'test',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
When I check my class path:
C:\>echo %CLASSPATH%
C:\Program Files (x86)\Java\jdk1.7.0_67\bin.;C:\Program Files (x86)\Java\jre7\li
b\ext\QTJava.zip
I have the JDBC file postgresql-9.3-1102.jdbc41.jar in the lib folder listed above.
Error Message from Django
File "C:\jython2.7b2\Lib\site-packages\django\db\utils.py", line 131, in load_backend raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'doj.db.backends.postgresql' isn't an available
database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: No module named schema
I believe the problem is that you are using the wrong version of Django.
Jython-Django is compatible only starting from 1.7.
See https://docs.djangoproject.com/en/1.6/howto/jython/

Django MongoDB Engine connection failure

[SOLVED] After successfully completing the django tutorial, I have tried to use mongoDB as a database, with Django MongoDB Engine. This is the database configuration in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': 'test',
'HOST': 'localhost',
'PORT': 27017,
# 'OPTIONS' : {
# 'slave_okay' : True,
# }
}
}
And this is the error message I get, after running python manage.py syncdb
:
raise AutoReconnect("could not find master/primary")
pymongo.errors.AutoReconnect: could not find master/primary
I got this error, even after shutting down the mongoDB server, so I figured out that this needed to be a connection issue. I posted an answer on how I solved this.
Using Ubuntu 12.04 LTS x64, Python 2.7, django 1.4.2, mongoDB x86_64 2.2.1 (clean new install)
The way I solved this is so simple that I am almost ashamed at myself for asking the question in the first place, but I hope it will be useful:
I simply upgraded the Django MongoDB Engine by typing into the terminal:
sudo pip install git+https://github.com/django-nonrel/mongodb-engine --upgrade
And that's it.
Can you try running ...
db.repairDatabase()
... from the mongo terminal?