SQL Server SPID returns after being killed - sql-server

I have a SPID in my SQL Server 2008 R2 database that shouldn't be there. It was created on a copy database job and that database and job have long since been deleted.
The SPID however did not disappear and tries to reconnect to my database every 1 minute and is filling up my error log.
I tried using the KILL ## command where ## is the process id but it just comes back with a new session id.
I have restarted the server made sure all possibly associated jobs are completed.
Does anybody know how I can end this SPID for good?
When it tries to run every minute it gives me this error message in my logs:
Log Name: Application
Source: MSSQLSERVER
Date: 1/2/2013 11:34:24 AM
Event ID: 18456
Task Category: Logon
Level: Information
Keywords: Classic,Audit Failure
User: DOMAIN\userid
Computer: server.domain.com
Description:
Login failed for user 'domain\userid. Reason: Failed to open the explicitly specified database. CLIENT: <local machine>]
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="MSSQLSERVER" />
<EventID Qualifiers="49152">18456</EventID>
<Level>0</Level>
<Task>4</Task>
<Keywords>0x90000000000000</Keywords>
<TimeCreated SystemTime="2013-01-02T19:34:24.000000000Z" />
<EventRecordID>19934006</EventRecordID>
<Channel>Application</Channel>
<Computer>server.domain.com</Computer>
<Security UserID="S-1-5-21-3027188495-1942244818-4144419180-3136" />
</System>
<EventData>
<Data>DOMAIN\userid</Data>
<Data> Reason: Failed to open the explicitly specified database.</Data>
<Data> [CLIENT: <local machine>]</Data>
<Binary>184800000E00000006000000410043004500500034000000070000006D00610073007400650072000000</Binary>
</EventData>
</Event>

The error indicates that you have an external (external to SQL Server) process trying to connect to SQL Server. The login fails because the process can't connect to the database, which I suspect has already been deleted. This process continues to retry to connect to the SQL Server. You can't kill the SPID, because the external process is designed to reconnect.
The process is associated with the copy database job. Did you create the copy-database job by right clicking the source database in the SSMS Object Manager, or some similar technique? The external process is probably associated with a DTS package.
In Windows Task Manager, select Processes and look for an Image Name similar to DTExec.exe or DTExecUI.exe. If you find one, then select to End Process. That should kill the process and stop the connections to SQL Server.
When you say "I have restarted the server" are you referring to restarting the computer or stopping and starting the SQL Server service? Restarting the SQL Server service won't stop this process.

Related

SQL Server Managed Backup for Windows Azure (SSMBackup2WA) stuck waiting for progress update

I have a database running on an azure vm with sql server. The db is in full recovery mode. The backup is configured through the web interface. Database and log backups have been working flawlessly for years. But recently the log backup was interrupted halfway through and the log backup process somehow got stuck. The following event has been logged every 5 minutes since then (reading log with managed_backup.sp_get_backup_diagnostics):
[SSMBackup2WAAdminXevent] Database Name = DB, Database ID = 777, Stage =
VerifyJobOutcome, Error Code = 0, Error Message = Warning, Additional Info = A
progress update hasn't been received from SQL Server in more than 30 minutes
for log backup. SSMBackup2WA will continue to wait.
SSMBackup2WA seem to be stuck waiting for a progress update never being received. This has resulted in no log backups being taken. The database backup have continued running without problem.
I have trouble finding the job/task used by SSMBackup2WA. I understand its not in the usual batch of SQL Server Agent jobs but somehow hidden.
My idea is to somehow cancel the existing job that is stuck in waiting loop but I have not figured out how.
I have tried to "reset" the backup process by turning off the backup and then turning it on again but that did not help.
I have no possibility to restart the sql server (and I don't know if that would help).
So since no one seemed to have an answer to this one I resorted to restarting the SQL-server. And after the restart the transaction log backup started working again!
What is interesting is the following log that appeared in the application event log during the restart. It does seem like there was a thread hanging indefinitely, waiting for an status update that never arrived. The restart seems to have taken care of it by killing this status thread and not restarting it again in the erroneous state it had ended up in.
Log Name: Application
Source: Microsoft SQL Server Automated Backup
Date: 1/15/2022 11:16:20 AM
Event ID: 57007
Task Category: None
Level: Warning
Keywords: Classic
User: N/A
Computer: wn-sqlserver1
Description:
[Warning] AutomatedBackupStatusMonitorError:
System.Exception:
Error in auto-backup status monitor thread --->
Microsoft.SqlServer.Management.IaaSAgentSqlQuery.Contract.IaaSAgentSqlQueryException:
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not
found or was not accessible. Verify that the instance name
is correct and that SQL Server is configured to allow remote
connections. (provider: Named Pipes Provider, error: 40 - Could
not open a connection to SQL Server) --->

SQL Server Log - Souce (SPID)

In checking Log File Viewer for noteworthy events I came across a log that I wanted to investigate.
Let's say the log notes the Source as SPID1234
My question:
Is this SPID tied to the actual connection that generated the log or is the SPID associated with the process that is writing this to the log?
In your scenario, the SPID1234, which means the session that is running this command has ID of 1234.
from here
A SPID in SQL Server is a Server Process ID. These process ID’s are
essentially sessions in SQL Server. Everytime an application connects
to SQL Server, a new connection (or SPID) is created. This connection
has a defined scope and memory space and cannot interact with other
SPIDs. The term SPID is synonymous with Connection, or Session.
SPID in Transaction Log - is ID of the process which originated the transaction, which was written into Transaction Log

SQL Server 2012 Logon exception

I have 2 applications connecting to the same database, when starting each individually both are fine. When I start them in the same time one of them will get logon exceptions as you may see below, this happening in 99% of my tries (so very rarely they are fine together).
And it is always the same application that gets the exceptions (1):
an application that's doing queries over the database
an application that connects to the service broker (this one work in all cases)
The 1st app will crash if I delay the start of the 2nd.
Here are some sql server logs:
2015-09-18 07:27:20.43 Logon Error: 18456, Severity: 14, State: 38.
2015-09-18 07:27:20.43 Logon Login failed for user 'domain\user'. Reason: Failed to open the explicitly specified database 'dbname'. [CLIENT: <local machine>]
2015-09-18 07:27:21.32 spid55 Setting database option ENABLE_BROKER to ON for database 'dbname'.
In SQL Server logs it is always like that, 2 line Logon error and then the ENABLE_BROKER line. I'm thinking that the service broker has something to do with the previous 2.
Details about envirenmont: SQL Server 11.0.3153.0 - 64 bit, Windows 7 (7601) running on a VM.
Because your database is in single-user mode. With single-user mode, only one client can connect to the database.
Change it to mulptile-user mode
GO
ALTER DATABASE AdventureWorks2012
SET MULTI_USER;
You can read more for the single-user mode here: https://msdn.microsoft.com/en-us/library/ms345598.aspx?
Finally i found what was causing this, it was the below alter database statement for which I don't see it's usage for now (while using the service broker it should be enabled by the db admin and not each time when the app is restarted). After removing that code everything seems fine.
ALTER DATABASE [dbname] SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE;
Inherited code fun :-) (not)

Manually start Oracle Database

I have a Oracle DB in my computer, but when i have this DB my computer start very slowly. I decide to disable Oracle services in msconfig. I disable a follow services:
OracleMTSRecoveryService
OracleServiceXE
OracleXEClrAgent
OracleXETNSListener
But sometimes I need using a Oracle Database. I try run in windows admin tools in services. I run all Oracle services:
OracleJobScheduler
OracleMTSRecoveryService
OracleServiceXE
OracleXEClrAgent
OracleXETNSListener
All services have state set a running.
But when i run SQL Developer and try connect to my database i get this error:
An error was encountered performing the requested operation:
ORA-01033: ORACLE initialization or shutdown in progress
01033. 00000 - "ORACLE initialization or shutdown in progress" Cause: An attempt was made to log on while Oracle is being started up
or shutdown. Action: Wait a few minutes. Then retry the operation. Vendor code 1033
Why? How to correctly run database in manually case?
Login to sqlplus as SYSDBA (for instance with "sqlplus /as SYSDBA" on command line).
It probably says "connected to an idle instance". In that case , you can start the database with "startup".
Because you have been fiddling with the startup services there might be other steps to take. But based on your information anything can be wrong.

Drop all active database connections failed for Server when executing KillAllProcesses

I need to perform a database restore from my application. Before doing this, I want to kill all processes as follows:
private void KillAllProcessesOnSMARTDatabases(Server targetServer)
{
targetServer.KillAllProcesses(SMART_DB);
targetServer.KillAllProcesses(SMART_HISTORY_DB);
targetServer.KillAllProcesses(SMART_METADATA_DB);
SqlConnection.ClearAllPools();
}
However, when the first KillAllProcesses is run, I get the following exception:
Microsoft.SqlServer.Management.Smo.FailedOperationException: Drop all active database connections failed for Server 'MYServer'. ---> Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: Only user processes can be killed.
The connection string used to create the server has sa credentials, however, the processes that need to be terminated are started under a different user. I tested the similar scenario and the test succeeded.
This started happening only recently. To me it appears there are some processes running that are not started by the user?
It would appear that your code is attempting to terminate all SQL Server Processes, which is not a good idea.
If you want to perform a database restore, you should set the database in question into either single_user mode or RESTRICTED_USER mode, the later being the most suitable.
Take a look at the following example of switching a database to RESTRICTED_USER mode and how to close any open user connections in the process.
How to: Set a Database to Single-User mode
You can use SMO to "kill" a particular database.
This will force a drop of all client connections to that database only and then drop the database itself.
Microsoft.SqlServer.Management.Smo.Server oServer = this.GetSmoServer();
oServer.KillDatabase(this.DatabaseName);

Resources