Sql communication link failure ошибка

I have had the same problem in two of my programs. My error was this:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

I spent several days to solve this problem. I have tested many approaches that have been mentioned in different web sites, but non of them worked. Finally I changed my code and found out what was the problem. I’ll try to tell you about different approaches and sum them up here.

While I was seeking the internet to find the solution for this error, I figured out that there are many solutions that worked for at least one person, but others say that it doesn’t work for them! why there are many approaches to this error?
It seems this error can occur generally when there is a problem in connecting to the server. Maybe the problem is because of the wrong query string or too many connections to the database.

So I suggest you to try all the solutions one by one and don’t give up!

Here are the solutions that I found on the internet and for each of them, there is at least on person who his problem has been solved with that solution.

Tip: For the solutions that you need to change the MySQL settings, you can refer to the following files:

  • Linux: /etc/mysql/my.cnf or /etc/my.cnf (depending on the Linux distribution and MySQL package used)

  • Windows: C:**ProgramData**MySQLMySQL Server 5.6my.ini (Notice it’s ProgramData, not Program Files)

Here are the solutions:

  • changing bind-address attribute:

    Uncomment bind-address attribute or change it to one of the following IPs:

     bind-address="127.0.0.1"
    

    or

     bind-address="0.0.0.0"
    
  • commenting out «skip-networking»

    If there is a skip-networking line in your MySQL config file, make it comment by adding # sign at the beginning of that line.

  • change «wait_timeout» and «interactive_timeout»

    Add these lines to the MySQL config file:

    [wait_timeout][1] = *number*
    
    interactive_timeout = *number*
    
    connect_timeout = *number*
    
  • Make sure Java isn’t translating ‘localhost’ to [:::1] instead of [127.0.0.1]

    Since MySQL recognizes 127.0.0.1 (IPv4) but not :::1 (IPv6)

    This could be avoided by using one of two approaches:

    1. In the connection string use 127.0.0.1 instead of localhost to avoid localhost being translated to :::1

    2. Run java with the option -Djava.net.preferIPv4Stack=true to force java to use IPv4 instead of IPv6. On Linux, this could also be achieved by running (or placing it inside /etc/profile:

       export _JAVA_OPTIONS="-Djava.net.preferIPv4Stack=true"
      
  • check Operating System proxy settings, firewalls and anti-virus programs

    Make sure the Firewall, or Anti-virus software isn’t blocking MySQL service.

    Stop iptables temporarily on linux. If iptables are misconfigured they may allow tcp packets to be sent to mysql port, but block tcp packets from coming back on the same connection.

     # Redhat enterprise and CentOS
     systemctl stop iptables.service
     # Other linux distros
     service iptables stop
    

    Stop anti-virus software on Windows.

  • change connection string

    Check your query string. your connection string should be some thing like this:

    dbName = "my_database";
    dbUserName = "root";
    dbPassword = "";
    String connectionString = "jdbc:mysql://localhost/" + dbName + "?user=" + dbUserName + "&password=" + dbPassword + "&useUnicode=true&characterEncoding=UTF-8";
    

Make sure you don’t have spaces in your string. All the connection string should be continues without any space characters.

Try to replace «localhost» with the loopback address 127.0.0.1.
Also try to add port number to your connection string, like:

String connectionString = "jdbc:mysql://localhost:3306/my_database?user=root&password=Pass&useUnicode=true&characterEncoding=UTF-8";

Usually default port for MySQL is 3306.

Don’t forget to change username and password to the username and password of your MySQL server.

  • update your JDK driver library file
  • test different JDK and JREs (like JDK 6 and 7)
  • don’t change max_allowed_packet

«max_allowed_packet» is a variable in MySQL config file that indicates the maximum packet size, not the maximum number of packets. So it will not help to solve this error.

  • change tomcat security

change TOMCAT6_SECURITY=yes to TOMCAT6_SECURITY=no

  • use validationQuery property

use validationQuery=»select now()» to make sure each query has responses

  • AutoReconnect

Add this code to your connection string:

&autoReconnect=true&failOverReadOnly=false&maxReconnects=10

Although non of these solutions worked for me, I suggest you to try them. Because there are some people who solved their problem with following these steps.

But what solved my problem?

My problem was that I had many SELECTs on database. Each time I was creating a connection and then closing it. Although I was closing the connection every time, but the system faced with many connections and gave me that error. What I did was that I defined my connection variable as a public (or private) variable for whole class and initialized it in the constructor. Then every time I just used that connection. It solved my problem and also increased my speed dramatically.

#Conclusion#
There is no simple and unique way to solve this problem. I suggest you to think about your own situation and choose above solutions. If you take this error at the beginning of the program and you are not able to connect to the database at all, you might have problem in your connection string. But If you take this error after several successful interaction to the database, the problem might be with number of connections and you may think about changing «wait_timeout» and other MySQL settings or rewrite your code how that reduce number of connections.

  • Remove From My Forums
  • Question

  • Hi,

    I have an SSIS package which runs subsequent packages in a batch.  When I run the main package through command line or a SQL job and connect to a data warehouse that is on the same machine, it runs without a problem.  When I try and connect to a warehouse on a remote machine (ideal configuration), it fails with this error:

    Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available.  Source: «Microsoft SQL Native Client»  Hresult: 0x80004005  Description: «Communication link failure». An OLE DB record is available.  Source: «Microsoft SQL Native Client»  Hresult: 0x80004005  Description: «Communication link failure». An OLE DB record is available.  Source: «Microsoft SQL Native Client»  Hresult: 0x80004005  Description: «TCP Provider: An existing connection was forcibly closed by the remote host. «.

    This seems to happen on random subpackages and isn’t always consistent. 

    My Master.dts.Config file has this connection info:

    <Configuration ConfiguredType=»Property» Path=»Package.Connections[Batch].Properties[ConnectionString]» ValueType=»String»>
      <ConfiguredValue>Data Source=RemoteServerName;Initial Catalog=DataWarehouse;Provider=SQLNCLI.1;Integrated Security=SSPI;</ConfiguredValue>
     </Configuration>

    Both machines have 64-bit operating system and 64-bit SQL software.

    Any help would be great.

    Thanks.

Answers

  • Do you have the same problem when using SQLOLEDB.1 rather than SQLNCLI.1

    Since you say it is random and inconsistent, it looks like the server accepts connections.

  • Remove From My Forums
  • Вопрос

  • Hi All,

    One of our SQL Server jobs has been failing for the past few days, its a package that calls other child packages. It is failing with the TCP IP and communication link failure errors.

    I have tried every possible thing on the google regarding this error

    1) Disabled the chimney.

    2) Tried Named pipes.

    3) Changed the source to retain the same connection to TRUE.

    4) Changed the option of executing the packages in concurrent to 0 instead of 3 which i previously had.

    Finally when i looked at the event viewer i am seeing the following error message around the same time the job is failing

    ESENT warnings

    Am i looking at the right place regarding the errors ? Please need suggestions.

    Thanks

Published: 01 Apr 2014
Last Modified Date: 24 Aug 2022

Issue

When refreshing an extract published to Tableau Server on Tableau Server, the following error message may be received: 

com.tableausoftware.nativeapi.dll.DataSourceException: Communication link failure
 

 Log files may include following error:

— ODBC Error ————————————————————-

File:         dbODBCProtocolImpl.cpp, Line: 2524

Error Code:   -1 (SQL_ERROR)

2338: ————-

2338: Error Record: 1

2338: Description:  ‘Communication link failure’

2338: SQLState:     08S01 (SQLSTATE_COMMUNICATION_LINK_FAILURE)

2338: Native Error: 14

2338: —————————————————————————-

Additionally, the same error might occur when refreshing a published data source from Tableau Desktop.
 

Environment

  • Tableau Server
  • Tableau Desktop
  • Netezza
  • Microsoft SQL Server
  • Teradata

Resolution

Work with your IT team to determine if there are interruptions to network traffic, network congestion, high server load on the datasource, other network disruptions, or hardware issues between your systems that are causing the connection to be lost.

Cause

The issue may be related to network congestion, high server load, or other network or hardware issues. 

Additional Information

For additional information about this topic, see the following articles and information below. 

  • General Network error», «Communication link failure», or «A transport-level error» message when an application connects to SQL Server
  • SQLSTATE=08501 — OR — Communication Link Failure

Specifically for Teradata data sources. a network communication failure can occur due to a variety of reasons. Here is a list of common causes of connectivity problems, in order from most likely to less likely:

  1. The Teradata session was forcibly logged off by Teradata Viewpoint, Teradata Manager, PMON, or some other administrator process that checks for session inactivity and aborts idle sessions. This can be checked by examining /var/log/messages on the Teradata Database node, to look for messages that indicate that a session was aborted. This is a common problem for JDBC connections in a connection pool, because JDBC connections in a connection pool may spend a significant portion of their lifetime being idle. The Teradata Database administrator should not forcibly log off idle Teradata sessions that are pooled JDBC connections, because that defeats the purpose of the JDBC connection pool.
  2. Network problem and/or transient network failure. This can include situations such as a laptop switching from a wired to a wireless network connection (or vice-versa), or connecting to, or disconnecting from, a VPN.
  3. Faulty network hardware, such as a faulty switch, router, or load balancer.
  4. Teradata Database restart occurred. This can be checked by examining /var/log/messages on the Teradata Database node, to look for messages that indicate that a Teradata Database restart occurred.




Are you having trouble connecting to a local MySQL database through DBeaver Community Edition? DBeaver fails to connect to a local MySQL database with the error “Communication link failure the last packet sent successfully to the server was 0 milliseconds ago“.

Here is a breakdown of this page:

  • Introduction
  • Solution
  • MySQL Configuration File
    • Location on macOS
    • Location on Linux
    • Location on Windows
  • Setting the MySQL port
  • Restarting MySQL
    • Restart MySQL on macOS
    • Restart MySQL on Linux
    • Restart MySQL on Windows

Introduction

The problem isn’t with DBeaver, in fact, if you installed another MySQL GUI tool, this issue would still occur.

This error occurs when the port used by MySQL is busy. To fix the communication link failure in DBeaver, we need to assign a port to MySQL.

In the solution below I used a Linux machine running Ubuntu 20.04 and verified using a Windows machine running Ubuntu 18.04 through WSL2 (Windows Subsystem for Linux).

Where possible I have provided alternative methods for both macOS and Windows.

This post also assumes you already have the correct database drivers installed and have created the MySQL connection.

DBeaver Communication Link Failure

Solution – Fixing communication link failure in DBeaver

First, you will need to locate your my.cnf file.

The my.cnf file is the configuration file used by MySQL. This MYSQL configuration file can reside in different locations, depending on your system and how it was installed.

Below are some locations where your installation’s my.conf could be for different operating systems.

Location of MySQL my.cnf file on MacOS or Linux

On macOS and Linux, you can find the MySQL configuration file in either the users home directory or within the /etc directory.

  • ~/.my.cnf
  • /etc/my.cnf

Location of MySQL my.cnf file on Windows

On a Windows machine, the MySQL configuration file can be in either the Windows directory or the root of the C drive.

In some cases, the my.cnf file can actually be a ini file, like so:

  • C:Windowsmy.ini
  • C:Windowsmy.cnf
  • C:my.ini
  • C:my.cnf

Once you have located the file, open it with your preferred editor. I will be using Nano.

nano /etc/mysql/my.cnf

You may need to append sudo to the command if you require higher security privileges.

Edit MySQL cnf file

Once you have opened the file using an editor, go to the bottom of the file and add the following configuration:

[mysqld]
port=3306 # or any other port
bind-address=0.0.0.0

Set the port to a port you know is open and not in use. By default, MySQL uses port 3306, but you can change this to another open port if required.

Save the file using Ctrl+O.

Now restart MySQL, there are multiple ways to do this, depending on your environment.

Restart MySQL on macOS or Linux

/etc/init.d/mysqld restart
# or 
systemctl restart mysqld

Restart MySQL on Windows

  • Open ‘Run’ by using Win key + R
  • Type ‘services.msc’
  • Now search for MySQL based on the version that is installed.
  • Click on ‘restart

If you found this post useful, check out how to Create SSH Connections in DBeaver.

Did this solution work for you? Leave a comment with your results.

Понравилась статья? Поделить с друзьями:
  • Spu orb произошли некритические ошибки
  • Spu orb произошла ошибка при обращении к базе
  • Spu orb users dbf ошибка
  • Sptd2 sys windows 10 ошибка
  • Spt aki escape from tarkov ошибка