I can connect to my MSSQL 2017 database via JDBC just fine, however when the database server is under heavy load, I get this connection error when running a query.
Have I simply maxed out what the server can do?
Maybe this is a NIC related issue?
Any performance settings adjustments to make?
com.microsoft.sqlserver.jdbc.SQLServerException:
The TCP/IP connection to the host 192.168.1.150, port 1433 has failed.
Error: "Connection timed out: no further information.
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.".
MS SQL Server have problems when are too many connections and worker threads from clients.
You can check current count of connections.
Select Count(*) FROM MASTER.DBO.SYSPROCESSES
There are dependencies between CPU cores and worker threads.
https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/configure-the-max-worker-threads-server-configuration-option?view=sql-server-2017
Max worker threads on your host.
Select max_workers_count from sys.dm_os_sys_info
Also you can see wait types THREADPOOL in TOP.
SELECT TOP 100
[Wait type] = wait_type,
[Wait time (s)] = wait_time_ms / 1000,
[% waiting] = CONVERT(DECIMAL(12,2), wait_time_ms * 100.0
/ SUM(wait_time_ms) OVER())
FROM sys.dm_os_wait_stats
WHERE wait_type NOT LIKE '%SLEEP%'
ORDER BY wait_time_ms DESC;
About waits threadpool:
https://www.sqlskills.com/help/waits/threadpool/
Check this version.
Or I don't understand situation and you have problem after X seconds after connection and work query.
Check query timeout in your application via the connection string something like "queryTimeout=..."
Related
I have the following connection string(get from a property of sql server):
Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\myUser\Desktop\adoBanche\Banche\bin\Debug\banche.mdf;Integrated Security=True;Connect Timeout=30
I don't understand what mean Timeout=30. Someone could explain what means?
That is the timeout to create the connection, NOT a timeout for commands executed over that connection.
See for instance http://www.connectionstrings.com/all-sql-server-connection-string-keywords/
(note that the property is "Connect Timeout" (or "Connection Timeout"), not just "Timeout")
From the comments:
It is not possible to set the command timeout through the connection string. However, the SqlCommand has a CommandTimeout property (derived from DbCommand) where you can set a timeout (in seconds) per command.
Do note that when you loop over query results with Read(), the timeout is reset on every read. The timeout is for each network request, not for the total connection.
Connection Timeout=30 means that the database server has 30 seconds to establish a connection.
Connection Timeout specifies the time limit (in seconds), within which the connection to the specified server must be made, otherwise an exception is thrown i.e. It specifies how long you will allow your program to be held up while it establishes a database connection.
DataSource=server;
InitialCatalog=database;
UserId=username;
Password=password;
Connection Timeout=30
SqlConnection.ConnectionTimeout. specifies how many seconds the SQL Server service has to respond to a connection attempt. This is always set as part of the connection string.
Notes:
The value is expressed in seconds, not milliseconds.
The default value is 30 seconds.
A value of 0 means to wait indefinitely and never time out.
In addition, SqlCommand.CommandTimeout specifies the timeout value of a specific query running on SQL Server, however this is set via the SqlConnection object/setting (depending on your programming language), and not in the connection string i.e. It specifies how long you will allow your program to be held up while the command is run.
Connect Timeout=30 means, within 30second sql server should establish the connection.other wise current connection request will be cancelled.It is used to avoid connection attempt to waits indefinitely.
How a connection works in a nutshell
A connection between a program and a database server relies on a handshake.
What this means is that when a connection is opened then the thread establishing the connection will send network packets to the database server. This thread will then pause until either network packets about this connection are received from the database server or when the connection timeout expires.
The connection timeout
The connection timeout is measured in seconds from the point the connection is opened.
When the timeout expires then the thread will continue, but it will do so having reported a connection failure.
If there is no value specified for connection timeout in the connection string then the default value is 30.
A value greater than zero means how many seconds before it gives up e.g. a value of 10 means to wait 10 seconds.
A value of 0 means to never give up waiting for the connection
Note: A value of 0 is not advised since it is possible for either the connection request packets or the server response packets to get lost. Will you seriously be prepared to wait even a day for a response that may never come?
What should I set my Connection Timeout value to?
This setting should depend on the speed of your network and how long you are prepared to allow a thread to wait for a response.
As an example, on a task that repeats hourly during the day, I know my network has always responded within one second so I set the connection timeout to a value of 2 just to be safe. I will then try again three times before giving up and either raising a support ticket or escalating a similar existing support ticket.
Test your own network speed and consider what to do when a connection fails as a one off, and also when it fails repeatedly and sporadically.
Gets the time to wait while trying to establish a connection before terminating the attempt and generating an error.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout%28v=vs.110%29.aspx
Maximum time between connection request and a timeout error. When the client tries to make a connection, if the timeout wait limit is reached, it will stop trying and raise an error.
Gets the time to wait while trying to establish a connection before terminating the attempt and generating an error.
(MSDN, SqlConnection.ConnectionTimeout Property, 2013)
By default connection timeout is 240 but if you are faceing the problem of connection time out then you can increase upto "300"
"Connection Timeout=300"
We have a WCF Data Service connecting to a SQL Server 2008 R2 database. When the service is trying to access data from the database the connection is getting timed out before the Connection Timeout value and the timeout exception is thrown.
This is the connection string:
Data Source=XXXX;Initial Catalog=XXXX;MultipleActiveResultSets=False;
Connection Timeout=80;Integrated Security=false;User ID=XXX;Password=XXX
In this connection string, even though we gave 80sec as the Connection Timeout, the connection gets timed out at around 700ms and throws below exception
System.Data.SqlClient.SqlException (0x80131904): Timeout
expired.
The timeout period elapsed prior to completion of the
operation or the server is not responding.
This is happening on some queries only.
Any help is appreciated.
It's not the ConnectionTimeout that causes the error; it's the CommandTimeout. See also this question.
Therefore, the solution is to set a higher value for CommandTimeout in case of more expensive queries.
This type of timeout can have three causes;
There's a deadlock somewhere
The database's statistics and/or query plan cache are incorrect
The query is too complex and needs to be tuned
Taken from the following links
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated
try to optimise the query as mentioned here
I had the same problem and google brought me here.
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
In my case, the mssql firewall port (default = 1433 TCP) was not yet open on the db server.
We currently have an issue that occurs roughly once a day on SQL 2005 database server, although the time it happens is not consistent.
Basically, the database grinds to a halt, and starts refusing connections with the following error message. This includes logging into SSMS:
A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - The specified network name is no longer available.)
Our CPU usage for SQL is usually around 15%, but when the DB is in it's broken state it's around 70%, so it's clearly doing something, even if no-one can connect. Even if I disable the web app that uses the database the CPU still doesn't go down.
I am unable to restart the SQLSERVER process as it is unresponsive, so I have to end up killing the process manually, which then puts the DB into Suspect/Recovery mode (which I can fix but it's a pain).
Below are some PerfMon stats I gathered when the DB was in it's broken state which might help. I have a bunch more if people want to request them:
Active Transactions: 2 (Never
Changes) Logical Connections: 34 (NC)
Process Blocked: 16 (NC) User
Connections: 30 (NC) Batch Request: 0
(NC) Active Jobs: 2 (NC) Log
Truncations: 596 (NC) Log Shrinks: 24
(NC) Longest Running Transaction
Time: 99 (NC)
I guess they key is finding out what the DB is using it's CPU on, but as I can't even log into SSMS this isn't possible with the standard methods.
Disturbingly, I can't even use the dedicated admin connection to get into SSMS. I get the same timout as with all other requests.
Any advice, reccomendations, or even sympathy, is much appreciated!
You will need to use the Profiler to determine what queries and process(es) may be causing this.
Whilst it is blocking normal connections, you might want to try going in under the Dedicated Admin Console connection. You will need to be in the sysadmin role of the database server to achieve this, in SSMS when you specify the server name prefix it with 'admin:' - this uses a different connection which is less likely to be blocked (but not impossible, just takes extreme circumstances).
You shouldn't use this DAC by default, you get access to the system tables and various other items you can not see normally, so you can also do a lot of damage with it.
Once in, you have a normal query window and can start looking at what is running, what's locked etc.
The dedicated admin connection is meant to help in these situations
Then, this script can tell you what has the open tran and the SQL running
SELECT s_tst.[session_id],
s_es.[login_name] AS [Login Name],
S_tdt.[database_transaction_begin_time] AS [Begin Time],
s_tdt.[database_transaction_log_record_count] AS [Log Records],
s_tdt.[database_transaction_log_bytes_used] AS [Log Bytes],
s_tdt.[database_transaction_log_bytes_reserved] AS [Log Reserved],
s_est.[text] AS [Last T-SQL Text],
s_eqp.[query_plan] AS [Last Query Plan]
FROM sys.dm_tran_database_transactions s_tdt
JOIN sys.dm_tran_session_transactions s_tst
ON s_tst.[transaction_id] = s_tdt.[transaction_id]
JOIN sys.[dm_exec_sessions] s_es
ON s_es.[session_id] = s_tst.[session_id]
JOIN sys.dm_exec_connections s_ec
ON s_ec.[session_id] = s_tst.[session_id]
LEFT OUTER JOIN sys.dm_exec_requests s_er
ON s_er.[session_id] = s_tst.[session_id]
CROSS APPLY sys.dm_exec_sql_text (s_ec.[most_recent_sql_handle]) AS s_est
OUTER APPLY sys.dm_exec_query_plan (s_er.[plan_handle]) AS s_eqp
ORDER BY [Begin Time] ASC;
Finally, SQL Server 2005 has a default trace running: you may be able to use this to find out what went wrong
Im trying to execute a stored procedure and simply insert its results in a temporary table, and I'm getting the following message:
The operation could not be performed because OLE DB provider "SQLNCLI"
for linked server "MyServerName" was unable to begin a distributed
transaction. OLE DB provider "SQLNCLI" for linked server
"MyServerName" returned message "No transaction is active.".
My query looks like this:
INSERT INTO #TABLE
EXEC MyServerName.MyDatabase.dbo.MyStoredProcedure Param1, Param2, Param3
Exact column number, names, the problem is not the result.
MSDTC is allowed and started in both computers, Remote procedure calling too.
The machines are not in the same domain, but I can execute remote queries from my machine and get the result. I can even execute the stored procedure and see its results, I just can't insert it in another table.
EDIT
Oh I forgot to mention, the stored procedure doesn't fire any trigger. It only inserts records in temporary tables which it creates itself for data treating.
Well, after following lots of tutorials and researching a lot about it, I had changed all the configuration I thought was necessary for it to work, but it still didn't.
Today we had to force a power reboot on our development server because of a faulty no-break, and when we booted up the server, guess what? It works!
So just for the record, I've changed some specific MSDTC configuration, added it as a linked server and allowed RPC IN and OUT, and changed the RPC configuration for 'NO AUTHENTICATION REQUIRED' or something like that.
I remember reading somewhere that after you changed this configuration, a reboot was required, even though Windows says that it has already restarted the service.
I had rebooted my server like... twice since I changed it, and it still didn't work. But as today, after a complete turn off and turn on, it works!
As for the syntax, I kept the same.
You also have to check the DNS name resolution in the IP network configuration.
For example, you have a server called server-a.mydomain.com and another one called server-b.otherdomain.com, log in the server-a and do a "ping server-b" (without the domain).
If it responds "Ping request could not find host server-b. Please check the name and try again." that is the problem.
Go to the Control Pannel > Network Connections > Right click in the network card > properties > Internet Protocol > Properties > Advanced > DNS > Append this DNS suffix in order.
And here add the local domain: mydomain.com and then add the remote domain: otherdomain.com
Click OK until you exit
Now if you do the "ping server-b" it should repond something like:
Pinging server-b.otherdomain.com [192.168.1.2] with 32 bytes of data:
Reply from 192.168.1.2: bytes=32 time=12ms TTL=64 Reply from
192.168.1.2: bytes=32 time=9ms TTL=64
Now try to again to execute the distributed transaction.
I had the luxury of safely restarting the SQL Server services on both sides of the Linked Server connection. I did not have to reboot the machines.
Have you tried using openquery?
insert into table select * from openquery(myservername, 'exec mydatabase.dbo.mystoredproc param1, param2, param3')
What would cause a query being done in Management Studio to get suspended?
I perform a simple select top 60000 from a table (which has 11 million rows) and the results come back within a sec or two.
I change the query to top 70000 and the results take up to 40 min.
From doing a bit of searching on another but related issue I came across someone using DBCC FREEPROCCACHE to fix it.
I run DBCC FREEPROCCACHE and then redo the query for 70000 and it seemmed to work.
However, the issue still occurs with a different query.
I increase to say 90000 or if I try to open the table using [Right->Open Table], it pulls about 8000 records and stops.
Checking the activity log for when I do the Open Table shows the session has been suspended with a wait type of "Async_Network_IO". For the session running the select of 90000 the status is "Sleeping", this is the same status for the above select 70000 query which did return but in 45min. It is strange to me that the status shows "Sleeping" and it does not appear to be changing to "Runable" (I have the activiy monitor refreshing ever 30sec).
Additional notes:
I am not running both the Open Table and select 90000 at the same time. All queries are done one at a time.
I am running 32bit SQL Server 2005 SP2 CU9. I tried upgrading to SP3 but ran into install failurs. The issues was occuring prior to me trying this upgrade.
Server setup is an Active/Active cluster the issue occurs on either node, and the other instance does not have this issue.
I have ~20 other database on this same server instance but only this one DB is seeing the issue.
This database gets fairly large. It is currently at 76756.19MB. Data file is 11,513MB.
I am logged in locally on the Server box using Remote Desktop.
The wait type "Async_Network_IO" means that its waiting for the client to retrieve the result set as SQL Server's network buffer is full. Why your client isn't picking up the data in a timely manner I can't say.
The other case it can happen is with linked servers when SQL Server is querying a remote table, in this case SQL Server is waiting for the remote server to respond.
Something worth looking at is virus scanners, if they are monitoring network connections sometimes they can get lagged, its often apparent by them hogging all the CPU.
Suspended means it is waiting on a resource and will resume when it gets its resource. Judging from the sizes you are pulling back, it seems you are in an OLAP type of query.
Try the following things:
Use NOLOCK or set the TRANSACTION ISOLATION LEVEL at the top of the query
Check your execution plan and tune the query to be more efficient