I am using spring boot with SQL server. On application startup or running integration test, it takes 1 - 2 minutes to load. The spring debug log shows that most of the time is consumed in getting JDBC connection. Below is the log snippet.
2014-11-18_15:54:54.604 [main] DEBUG o.s.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
2014-11-18_15:55:58.213 [main] DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
I am using net.sourceforge.jtds ver 1.3.1 driver and sql server version 2012. Can anyone please help how I can fix this issue.
Related
I am using .NET Core MVC API (.NET Core 6.0), actually just C# in general.
I need to deploy a .NET API on a linux server. However, it seems to that I can't connect to the SQL Server that is running on the same server.
This is the error from .NET
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request.
System.Exception: Cannot connect to SQL Server Browser. Ensure SQL Server Browser has been started.
---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000001, 11): Resource temporarily unavailable
at System.Net.Dns.GetHostEntryOrAddressesCore(String hostName, Boolean justAddresses, AddressFamily addressFamily, ValueStopwatch stopwatch)
This is the error I get from curl
{"error":true,"message":"Cannot connect to SQL Server Browser. Ensure SQL Server Browser has been started."}
Keep in mind that both the API and the database are on the same server.
I think the problem comes from .NET. I am able to connect to the database on the server using the API locally.
This is the connection string in my appsettings.json
"ConnectionStrings": {
"ConnStr": "Data Source=<PUBLICIP>;Initial Catalog=<DBNAME>;User Id=<USER>;Password=<PASS>;Integrated Security=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",=
"lockerConStr": ""
}
Any help would be greatly appreciated!
Things I have tried:
Changed Data Source to (local) - (doesn't work)
Added Encrypt= false;Trusted_connection=True; - (doesn't work)
Connect to the SQL Server from local version of the .NET API (successful)
Connect to the SQL Server using a python script running from the same server (successful)
Specified Driver in the connection string (doesn't work)
The python script (not sure if this would help)
import pyodbc
conn = pyodbc.connect('Driver={ODBC Driver 17 for SQL Server};'
'Server=<PUBLICIP>;'
'Database=<DBNAME>;'
'UID=<USER>;'
'PWD=<PWD>;'
'Trusted_Connection=no;')
cursor = conn.cursor()
cursor.execute('SELECT * FROM users')
I deleted the whole project on the server and cloned the git back.
After carefully reading the error, I noticed that it's running using my local connection string (not sure why, I changed the connection string on the server). I also rebuilt the solution and republished it a few times. Not sure what changed.
But I finally got it to work!
After upgrading to spring boot 2.6.6 in production, constantly experiencing db connection issues
like
com.microsoft.sqlserver.jdbc.SQLServerException: The query has timed out. The query has timed out.
connection is broken
current version for jdbc is 5.3.18 and r2dbc is 1.1.7
Does anybody experiencing the same issue ?
I have a Spring Boot (1.5.17) web application with Tomcat JDBC connection pool (8.5.34) configured as follows:
primary.datasource.tomcat.testOnBorrow=true
primary.datasource.validationQuery=SELECT 1
primary.datasource.validationInterval=35000
primary.datasource.initial-size=10
primary.datasource.max-active=50
primary.datasource.max-idle=20
primary.datasource.min-idle=10
Now if I restart the database server (SQL Server) I get the com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed exception and the connection pool does not recover.
So what am I doing wrong?
I have found the error. I made a mistake while writing the configuration key primary.datasource.tomcat.testOnBorrow. It should be primary.datasource.testOnBorrow. And now it is working fine. The connection pool recovers almost immediately after database server restarts.
Here is my final configuration for anyone if they are having similar problems.
primary.datasource.testOnBorrow=true
primary.datasource.validationQuery=SELECT 1
primary.datasource.validationInterval=55000
primary.datasource.initial-size=5
primary.datasource.min-idle=5
primary.datasource.max-idle=10
primary.datasource.max-active=20
primary.datasource.removeAbandoned=true
I'm working on Spring project using Tomcat as server, My database in SQL Server 2008 r2. whenever I enable the TCP/IP protocol of SQL Server, if I restert the Tomcat Server it gives me this error:
Starting Tomcat v7.0 Server at localhost' has encountered a problem
Server Tomcat v7.0 Server at localhost was unable to start within 45
seconds. If the server requires more time, try increasing the timeout
in the server editor.
I tried to inrease in start time but I encountred the same problem. If disable the TCP/IP protocol of SQL Server and I restert the Tomcat Server it works.
Best regards.
Our environment is:
Windows Server 2003, Service Pack 2
SQL Server Express 2005
SQLServer JDBC driver 1.2 (also tried Jtds)
Sun JDK 1.6 (we tried this on JDK 1.5 as well)
There is no virus protection software on the host, and no firewall is enabled.
We have Web application deployed in JBOSS 4.0.2.
Our problem is that the JDBC connection to SQL server periodically gets disconnected, and then we can't reconnect to the database at all, unless we physically restart the server on which JBOSS deployed.
we are getting following error in log.
Software caused connect on abort: recv
failed
Note: We are able to connect to database using sample java test class.
Any suggestions would be most appreciated, as this is a serious, mission-criticial problem for us right now.
Can you access the SQL Server using Management Studio? If so how many connections are open?
Do you close your connections after querying?
What does the Task Manager tell, service still running; mem/cpu usage.
Its a long shot but do you have enough disk space on C: and data-drive?