How do I solve “could not create connection to database” error?

It’s hard to solve a problem without looking at the error log. Just go to pastebin.com. Copy the error you got and paste in the white space in the pastebin link and share the link after creating it

Ok thank you

what are you trying t o do,are trying to set up openmrs>

@hafizurahman have you used pastebin.com like @jwnasambu told you? If you did please paste here the link to pastebin that we could follow to help you.

hello, I have the same problem as the original poster. My setup: virtualbox virtual machine centos 7 tomcat 7.0.76 mysql 5.6.47 war file 2.2.0 I can access the server as seen from the screenshot

any suggestions? and where I can find the error log? thank you

Now I tried core 2.3.0, still with same error tomcat service log can be checked in: https://pastebin.com/wiDPTFR2 Hopefully someone can help

So when searching for the error message in your logs, I came across this StackOverflow answer, which suggests that the issue is caused by a change in the default SELinux configuration on RHEL 7.4 and later (and, consequently, on CentOS) which, by default, disallows Tomcat from connecting to a local database via TCP. The answer there suggests disabling SELinux, which is one way to solve the issue. This other answer suggests a command that should allow Tomcat to connect to MySQL without totally disabling SELinux. Finally, this blog post has a suggested SELinux policy which will default to allowing Tomcat to connect to MySQL with SELinux running.

I don’t have any experience with any of the suggested fixes, but you might try that and see if the issue resolves itself.

1 Like

I will try to use the localhost which is a unix socket as far as I understand, and I will check your suggestions about SELinux, also as I understood there is another solution by using different server for mysql. I will try these solutions and come back to you. your help is much appreciated @ibacher

Disabling SELinux done the trick, even it is not good to disable it, but at least now I know the origin of the problem, thank you so much :slight_smile:

1 Like

Some notes for people who works with CentOS 7 to configure SELinux permissions:

to check SELinux status:

sestatus

to see the permissions for tomcat

getsebool -a | grep tomcat

to allow tomcat to connect to database

setsebool tomcat_can_network_connect_db 1

to make this change permanent

setsebool -P tomcat_can_network_connect_db 1

to change the status for SELinux

sudo nano /etc/selinux/config

I hope this can help other people :slight_smile:

1 Like

Do you have a similar solution for windows? I’m also running into the same DB connection issue

Actually, I didn’t have a database connection error in windows, maybe you didn’t start the application as an administrator, try right-clicking and press run as administrator and post the download link for the version you use so I can try it now as I didn’t use the software since last year

1 Like

Can you try with this: https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.64/bin/ Openmrs-core 2.4.x

you use the war (for enterprise) version?

I clone the repository (Openmrs core 2.4.x), then build the war file using mvn clean package

I don’t know how these things work, on windows I only used the standalone version

Edit:

do you need to build the war file for some specific reason? you can get it ready built from here: https://sourceforge.net/projects/openmrs/files/releases/OpenMRS_Platform_2.4.0/openmrs.war/download

you install tomcat, install a database, and deploy the war file

other versions also available here:

https://openmrs.org/download/

It is not an issue of war file. It is something related to Tomcat server access on db

I don’t know how to use the clone and building tools, so i will not be able to replicate your situation

I will try using the ready made war file

i already installed tomcat

you use mysql database?

yes, I’m using mysql db

ok, I will use mysql and see if I get any errors

@ankitm you used “simple” or “advanced” in the OpenMRS Core 2.4.0 Installation Wizard?