can not connect a DB instance Running the PostgreSQL Database Engine to pgadmin4 - database

I want to configure Postgres with pgadmin on centos7. but unable to create a server on pgadmin.
I edited file /var/lib/pgsql/data/pg_hba.conf as this :
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
and edited file /var/lib/pgsql/data/postgresql.conf as this :
listen_addresses = '*'
port = 5432
the I restarted PostgreSQL with this command: sudo systemctl restart postgresql
and here is my configuration in pgadmin4:
but after I click on the save button nothing happens
so my question is how to configure Postgres with pgadmin on centos7, and what I've done wrong in this process?

Related

Error 20009 (severity 9): Unable to connect: Adaptive Server is unavailable or does not exist OS error 111, "Connection refused"

I tried to connect to MSSQl database using freetds, unixODBC in raspberry pi 4.Below are my settings.
[fred]
host = 109.*.*.* # Remote Sql Server's IP addr
port = 1433 # this is default
tds version = 7.4 # this is by the time i post this
client charset =UTF-8
[test]
Driver = FreeTDS
Description = MSSQL Server
Trace = No
Server = fred # IP or host name of the Sql Server
Port = 1433 # This is default
TDS_Version = 7.4
[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/arm-linux-gnueabihf/odbc/libtdsodbc.so
Setup=/usr/lib/arm-linux-gnueabihf/odbc/libtdsS.so
UsageCount=1
I have tested with tsql -H ip -U username -P password but the error still persists. I have also installed pyodbc. I am trying to connect from Pi to MS SQl Server Management studio. Could anyone suggest me to have a successful connection to database? I appreciate all the approaches.
I was able to shrug off this error by using the following call:
bsqldb -S $servername:1433 -D $databasename -U $username -P $password -i $inputfile
As far as documentation states, a qualified server name with the port number allows to bypass the related .conf settings.

Can't Connect to External SQL Server From Docker Container

I've developed a SpringBoot(Java) application that calls out to an external SQL Server on port 1433. The SQL Server instance is located on-premises (not local SQL Server instances). However, it's reachable from my desktop using either IntelliJ or SQL Clients.
I am using the Microsoft SQL Server JDBC connector to communicate with the instances.
If I run the app from IntelliJ all is well, the app can call the SQL Server, execute the command and returns a resultsset.
However, now I'm trying to Dockerize the api app. The container does the usual SpringBoot initialization but when it tries to call the SQL Server I get the following error:
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host myexternalsqlserver.domain, port 1433 has failed. Error: "myexternalsqlserver.domain. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:234)
at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:285)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2434)
at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:659)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2546)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2216)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:2067)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1204)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:825)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
at com.symetra.SdsApi.SqlConnector.getResultSet(SqlConnector.java:26)
This is my Docker file
FROM openjdk:11.0.4-jre-slim-buster
VOLUME /tmp
COPY target/myapi-1.0-SNAPSHOT.jar app.jar
EXPOSE 8080
EXPOSE 1433
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=docker -jar /app.jar" ]
And these are the Docker commands I use to build and run the container:
docker build -t myapi . && docker run -p 8080:8080 -p 1433:1433 --name myapi myapi "java","-jar","myapi-1.0-SNAPSHOT.jar"
I don't think the mapping of port 1433 is necessary, it's just an experiment. I should be able to communicate outside of my container through to port 1433 on the host. Port 1433 isn't being blocked on the host because I have no problems running this outside the container.
Finally, this is the connection string I'm using:
//Create Connection Url.
String connectionUrl="jdbc:sqlserver://myexternalsqlserver.domain:1433;database=mydb;user=MyUser;password=MyPassword";
I'm not sure what I'm doing wrong here. I'm wondering if I need to set up Docker networking.
Thanks for your help!
It should work.
NB I'm assuming myexternalsqlserver.domain is not what you're using.
One way to test your container is to shell into it (or create a variant) and try resolving the SQL Server's host name:
docker run --interactive --tty openjdk:11.0.4-jre-slim-buster /bin/bash
# then from within the container's shell
apt update && apt install -y dnsutils
nslookup ${SQL_SERVER}
If that succeeds, it's your code.
If not, it's the network.
NB Your container need not publish 1443 (--publish=1433:1433) since it's consuming that port (on the SQL Server) not exposing the port itself.
The same issue bugged me for days and finally was able to solve it by following the steps below.
In my case the SQL server was hosted on Azure managed instance and exposed a private endpoint. The docker was able to resolve the DNS name of the Azure managed instance to a private IP address (as expected ). But this resolved IP was considered by the docker network/bridge as a locally running application because upon inspecting docker's bridge (docker network inspect bridge)The subnet of the bridge was found to be a range of IP addresses where the resolved IP of the SQL server also falls. Hence, the docker assumed the SQL server to be hosted in the same local network and not outside (here enterprise network). In my case the Windows VM I was working was already on the private network of the enterprise.
Solution:
In the docker desktop -> settings -> Docker Engine json file, add a new key value pair
"bip": "<local IP address range which is outside of the resolved sql server IP>".
Restart the docker desktop and the issue should be solved.

Unable to connect SQL Server with ODBC drivers on linux

I have install the driver odbc 2.3.0 on linux by this reference: https://www.microsoft.com/en-ca/download/confirmation.aspx?id=28160
All these steps work correctly.
This is my configation:
SERVER:
Oracle server is on linux
SQL Server is on windows
SQL Server:
My login and password are the same. It's: demo
When I use cmd and I use the command: "ipconfig", I can get my IP
My IP is: 192.168.0.106
This is how I do my connection manually and it work:
After the installation, i have configure my files odbinst.ini and odbc.ini
This is my file odbcinst.ini:
This is my file odbc.ini:
This is where my driver is download:
My instance name is MSSQLSERVER and TCP-IP and listen all are enable:
Dynamic port is blank and static port is 1433:
As you see, I can be connect on localhost with the command line:
sqlcmd -S 192.168.0.106 -d demo -U demo -P demo
But, I can't connect with my Oracle server on putty with this command line:
isql MSSQLSERVER -v
Why it don't work?
The server is start
Allows remotely connexion is enable
I have add port 1433 in firewall setting
I tried to disable the firewall, nothing change
Something is wrong in my configuration?
Problem reseolve :
Change sqlServer Localhost to SqlServer.
You can't connect 2 server if they are on localhost. You need an oracle SQL Server and SQlServer working not on LocalHost

How to connect sql server using docker on mac?

I am trying to connect to sql server using docker. I have successfully enabled the container using this command
sudo docker run -d --name aakash -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Maximus6hero#" -p 1434:1434 microsoft/mssql-server-linux
docker ps
3e41723b93d5 microsoft/mssql-server-linux "/opt/mssql/bin/sqls…" About an hour ago Up About an hour 1433/tcp, 0.0.0.0:1434->1434/tcp aakash
It shows that my container is running.
But when i try to connect using db visualizer it throws an error.
The TCP/IP connection to the host localhost, port 1434 has failed. Error: "The driver received an unexpected pre-login response. Verify the connection properties and check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. This driver can be used only with SQL Server 2000 or later.". ClientConnectionId:6a802ae0-7203-411d-a599-4c1de997d843.
I also have windows pc with me, and i can connect easily using sql server management studio. Even i can connect others pc using that windows pc. But when i try to connect my mac to windows pc using its ip it also gives the same error.
I have enabled tcp/ip connection on windows using sql server configuration manager. But there is no such thing on mac.
You might be getting this error on your MAC because when you run the docker in the background, it uses only 2GB of memory by default which is insufficient to run the SQL server as it needs minimum of 3.25 GB and ideally, we should point it to 4GB of memory. Update the preferences section with above details on your docker. Save and restart the docker and you may check the below steps to see if that might help you for your MAC. I did this using Azure Data Studio and Docker.
Once you have Saved and restart the docker with 4GB of Memory Allocation for docker to run, all you'd need to do is pull the docker image of the sql server and download it. this can be done by below commands on your terminal . FYI, I am using bash commands below:
Command 1:
sudo docker pull mcr.microsoft.com/mssql/server:2017-latest
This will pull the latest vesion docker image and download. Once done, you need to set your SQL authentication on the server for your database. Follow below commands:
Command 2:
sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<SetYourPasswordHere>' \
-p 1433:1433 --name sql1 \
-d mcr.microsoft.com/mssql/server:2017-latest
This sets your password and uses the port 1433 for SQL server (which is the default port). To confirm if the image has been created and the SQL server is running on docker, execute the below command to check log(s).
Command 3:
docker ps
To check all instances in your history of dockers( i.e. if you already had dockers installed before you are attempting this SQL connection/execution), run the below command and it will give you all the logs of all instances you have created
Command 4:
docker ps -a
or
docker ps -all
Once, you have completed above steps and see that the docker has created SQL instance, you need to go to Azure Data Studio and set the below credentials to access the server that you just created above using Docker.
Server: localhost
Authentication Type: SQL Authentication
Username: sa
Password: <Check Command 2 to see what you entered in the password where it says SetYourPasswordHere>
Hope this helps in your tryst with running SQL server on your MAC. All the Best!

Trouble connecting to SQL Server with sqlcmd from inside Docker

Working with debian linux inside a docker contaier. I have sqlcmd working properly and the neseccary drivers are installed and locatable. I know the server exists:
root#0feafecac36f:/home/shiny# nmap -p 31010 -sT xxx.xxx.xxx.xxx
Starting Nmap 7.60 ( https://nmap.org ) at 2018-01-25 20:46 UTC
Nmap scan report for nile-h.tmthk.org (xxx.xxx.xxx.xxx)
Host is up (0.019s latency).
PORT STATE SERVICE
31010/tcp filtered unknown
Nmap done: 1 IP address (1 host up) scanned in 0.59 seconds
But, for the life of me, I cannot figure out how to connect using sqlcmd, and I am not sure what tricks I have at my disposal to help. This command results in an error:
sqlcmd -S nile-h.tmthk.org,31010 -U "*********" -P "********"
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 13 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..
I have confirmed that the user name and password are correct. So, what could be going on here? Any ideas? I've tried many iterations of the sqlcmd to try to get it right but so far nothing is working.
EDIT: Telnet
root#0feafecac36f:/home/shiny# telnet xxx.xxx.xxx.xxx 31010
Trying xxx.xxx.xxx.xxx...
telnet: Unable to connect to remote host: Connection refused
EDIT: tcptraceroute
root#0feafecac36f:/home/shiny# tcptraceroute xxx.xxx.xxx.xxx 31010
Selected device eth0, address 172.17.0.2, port 33859 for outgoing packets
Tracing the path to xxx.xxx.xxx.xxx on TCP port 31010, 30 hops max
1 172.17.0.1 0.241 ms 0.179 ms 0.156 ms
2 nile-h.tmthk.org (xxx.xxx.xxx.xxx) [closed] 1012.571 ms 1003.511 ms 1003.485 ms
EDIT: ip route get
root#0feafecac36f:/home/shiny# ip route get xxx.xxx.xxx.xxx
xxx.xxx.xxx.xxx via 172.17.0.1 dev eth0 src 172.17.0.2
cache
EDIT: Dockerfile
FROM r-base:3.4.0
RUN apt-get update && apt-get install -y \
apt-utils \
curl \
libcurl4-openssl-dev \
libssl-dev \
r-cran-rjava \
gnupg2 \
r-cran-rodbc \
unixodbc \
unixodbc-dev \
apt-transport-https \
debconf-utils \
gcc \
libct4 \
libsybdb5 \
tdsodbc \
sqsh \
mlocate \
sudo \
gfortran
ENV PATH="/opt/mssql-tools/bin:${PATH}"
RUN useradd -u 5555 -m -d /home/shiny -c "shiny user" shiny
ADD . /home/shiny/
RUN chown -R shiny:shiny /home/shiny
RUN chmod 755 /home/shiny/install_sql.sh
WORKDIR /home/shiny
RUN Rscript installRpackages.R
RUN chmod 755 /home/shiny/install_sql.sh && /home/shiny/install_sql.sh
RUN R -e "install.packages('devtools')"
RUN R -e "devtools::install_github('rstudio/DT')"
RUN R -e "devtools::install_github('timelyportfolio/parcoords')"
RUN R -e "devtools::install_github('ropensci/plotly') ; library(plotly)"
RUN R -e "devtools::install_github('rstudio/crosstalk',force=TRUE) ; library(crosstalk)"
RUN R -e "install.packages(c('plotly'), dependencies = TRUE, repos='https://cran.rstudio.com/')"
RUN wget "http://security.debian.org/debian-security/pool/updates/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u7_amd64.deb"
RUN sudo apt install ./libssl1.0.0_1.0.1t-1+deb8u7_amd64.deb
USER shiny
EXPOSE 7777
CMD Rscript start.R
And finally, the install_sql.sh called by the Dockerfile:
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.10/prod.list > /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install msodbcsql
# optional: for bcp and sqlcmd
ACCEPT_EULA=Y apt-get install mssql-tools
# optional: for unixODBC development headers
apt-get install unixodbc-dev
Judging by the nmap output you have shared I believe this to be a firewall issue or the server SQL Server itself blocks access. According to man nmap:
The state is either open, filtered, closed, or unfiltered [... ] Filtered. means that a firewall, filter, or other network obstacle is blocking the port so that Nmap cannot tell whether it is open or closed.
Reading the sqlcmd output (A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible) also points in this direction according to this Microsoft post which also offers some possible solutions.
IF the SQL Server is managed by yourself, you may check its logs to see why it refuses your connection and also add a firewall rule to allow access from your container. IF that's not the case, you may need to talk with the admin of that server and ask him to add your IP in the firewall list/accepted connections list in the server's configuration file.
If firewall is not your issue, please try applying the below settings to your SQL Server and re-test the connection.
Set "Listen to All" to No in the SQL Server Configuration Manager >
SQL Server Network Configuration > Protocols for [instance name]. And
under IP Address change 127.0.0.1 to the [ip] used to connect. Don't
forget to restart the SQL Server!
Other tip: check your firewall (or temporaly disable it for testing).
Also allow remote connections in SQL Server properties > Connections.
See above posts.
Life safer was this command: nc -zv <ip> 1433
It should say Connection to 1433 port [tcp/ms-sql-s] succeeded!
The original source is here.
Reading from your question, I'm assuming you want to connect to your local SQL Server from inside Docker.
SQL Server can be connected to over TCP/IP:
Open SQL Server Configuration Manager and make sure TCP/IP is enabled;
Make sure SQL Server is listening on all IP addresses.

Resources