SQL Server ClosedConnectionException in vert.x

3phpmpom  于 2023-04-04  发布在  其他
关注(0)|答案(1)|浏览(147)

I am trying to insert data into a db. While inserting the data I am getting an issue from vert.x saying

vertx 4.4.0 error => io/vertx/sqlclient/ClosedConnectionException

   vertx 4.3.8 error => Fail to read any response from the server, the underlying connection might get lost unexpectedly.

This error is occurring every-time on INSERT in DB. But working on READ from DB

public static MSSQLPool createMssqlDbPool(Vertx vertx, DbConfig dbConfig) {

    MSSQLConnectOptions connectOptions = new MSSQLConnectOptions()
      .setHost(System.getenv().getOrDefault("DB_HOST", dbConfig.getHost()))
      .setPort(Integer.parseInt(System.getenv().getOrDefault("DB_PORT", dbConfig.getPort())))
      .setDatabase(System.getenv().getOrDefault("DB_NAME", dbConfig.getDatabase()))
      .setUser(System.getenv().getOrDefault("DB_USER", dbConfig.getUser()))
      .setPassword(System.getenv().getOrDefault("DB_PASSWORD", dbConfig.getPassword()));

    // Pool options
    PoolOptions poolOptions = new PoolOptions()
      .setMaxSize(5);

    LOG.info("DB connection : {}", connectOptions.toJson());

    return MSSQLPool.pool(vertx, connectOptions, poolOptions);

  }

I have tried a lot of things

  1. I added timeout from 3 seconds to 5 minutes but still getting the same error.
  2. I tried creating a new user for DB, still it doesn't work.
  3. I tried changing the version of the mssql-client.
  4. When i run the same code in lower environments its workinf fine. It gives error only on production. So i am not sure if we need to do changes in code or there should be some change in the DB side.

Now I am put of options as to why it is not working. Can you please help.

ldioqlga

ldioqlga1#

The error message you are receiving is indicating that the connection to the database is closed when you are trying to insert data. There could be various reasons for this error, such as:

  1. The connection pool size is too small, and all the connections are being used up by other requests. You could try increasing the pool size to see if it resolves the issue.
  2. There is an issue with the database server, such as a network outage, or the database server is overloaded.
  3. There could be an issue with the SQL query that you are using to insert the data. Please ensure that the query is correct and is not causing any issues.

To investigate the issue further, you could try adding some logging statements to your code to see where the error is occurring. You could also check the database server logs to see if there are any errors or warnings that could be related to this issue.

It might also be helpful to check the documentation for the MSSQLPool class to see if there are any additional configuration options or settings that you need to configure to avoid this issue.

相关问题