I have an sql 7.0 database with an Access 97 front end. We need to run a process every night to update the database. However, not all users disconnect from the front end and we get lock conflicts. It is not acceptable to have a person stay till the evening to manually kill all the spid's and i can't find any way to force all users off the database as you can in DB2. Also, we can't change the front end. Any idea how to force all users off of an sql server database (kill all spid's?) in an automated way. Thanks
I am working with an application unde mssql 6.5 ,sp4. We have a separate database for reporting on a different box. Each night we load a backup into the database from the production database.
I set up a stored procedure to kill all users connected to this reporting database just before the load.
THe job looks like this under scheduled tasks as a cmdexec:
Process Exit Code 1. ...[-b On error batch abort] [-O use Old ISQL behavior disables the following]<EOF> batch processingAuto console width scalingWide messagesdefault errorlevel is -1 vs 1 [-? show syntax summary (this screen)]
The killusersall is paramaterize sp that I pass the dbid of the database for whom I want all users killed. I need to put the stored procedure in the master because I egt the spid from sysprocesses.
I do not understand why the job died. Does it matter if I named the stored procedure as sp_killusersall instead of killusersall_sp which I used.
Can any one advise me about how to get the job to run? Any assistance will be greatly appreciated. Thanks you.
This is gonna be a quite long explanation of an understanding problem and I seriously hope that anyone can help me out here. Please look at the following example: use tempdb; create table T1 ( C1 varchar(80) not null default 'Empty' ,C2 uniqueidentifier not null default newid() ) go -- Add some rows set nocount on insert T1(C1) values('A') go 5 insert T1(C1) values('X') go 7 insert T1(C1) values('Y') go 9 insert T1(C1) values('Y') go 6 Now run the following two queries and include the actual execution plan: select distinct top 10 row_number() over(order by C1), C1 from T1
select top 10 row_number() over(order by C1), C1 from T1 You€˜ll get two different plans with the first one slightly more expansive than the second. What I do not understand is, why the optimizer does not ignore the DISTINCT in the first case. When I include a ROW_NUMBER() without partitioning (or, to e exact: with only one partition) as in the above query, every row will get a unique number, so all returned rows are already distinct, aren€™t they? But as this optimization possibility is so obvious and simple, I don€™t believe that the optimizer is wrong €“ rather I suppose that I€™m the on, who does not understand what€™s going on here. If you play around with some SELECTs, the difference between DISTINCT included and excluded can be very noticable. Take the following example: select distinct top 10 row_number() over(order by a.C1), a.C1, b.C1 from T1 as a inner join T1 as b on b.C2 = a.C2
select top 10 row_number() over(order by a.C1), a.C1, b.C1 from T1 as a inner join T1 as b on b.C2 = a.C2 where the (unnecessary?) DISTINCT in the first query holds responsible for 34% oft he total query costs, making the cost for the first query over twice as much as for the second. I€™ve tried to find at least one example where DISTINCT makes sense €“ but without success. In all my experiments (included the above, of course), always the same resultset is returned, regardless of DISTINCT or not. The problem has been detected using an OR-mapper (nHibernate), where the SQL code is automatically generated. Inside the code generation process, a ROW_NUMBER() columnn without partitioning is always added, as well as in many cases also DISTINCT. I€™d simply like to remove the DISTINCT keyword from the code generation, because it increases the performance dramatically in many cases. But fort he reasons mentioned above, I€™m not sure whether I can do this without risk. Any ideas are greatly appreciated.
AS DECLARE@UPLIDCount int DECLARE @OldUPLIDCount int SELECT @UPLIDCount = (SELECT Count(UPLID)/1000 AS adjcount FROM tblProvLicSpecloc WHERE DelDate is null OR DelDate > GETDATE())
IF EXISTS(SELECT var FROM tblDMaxVars WHERE var = 'UPLID Count') BEGIN SELECT @OldUPLIDCount = (SELECT var FROM tblDMaxVars WHERE var = 'UPLID Count') IF @UPLIDCount > @OldUPLIDCount BEGIN UPDATE tblDMaxVars SET value = '' + CAST((@UPLIDCount*1000) AS nvarchar(1000)) + '' WHERE var = 'UPLID Count' END END ELSE BEGIN INSERT INTO tblDMaxVars (var, value, description) VALUES ('UPLID Count', '' + CAST((@UPLIDCount*1000) AS nvarchar(1000)) + '', 'counts UPLID records and rounds down to the nearest thousand') END
GO
The table tblDMaxVars only has three columns, none of which are integers, yet I still return this error:
Code:
Syntax error converting the varchar value 'UPLID Count' to a column of data type int.
I'm trying to kill a bunch of processes in SQL 6.5 and I can't. I'm running the only machine with SQL tools installed on it (the server) and it won't let me kill them. I try the GUI screens and the Kill statement in ISQL_w. Is there any way around this?
I've stopped the SQL Server and rebooted the NT Server. Is there anyway I can get rid of these processes. They are locking some tables and keeping me from inserting data within my code. Very frustrating.
Hi there, Here we have got a asp.net application that was developed when database was sitting on SQL server 6.5. Now client has moved all of their databases to SQL server 2000. When the database was on 6.5 the previous development team has used oledb connections all over. As the databases have been moved to SQL server 2000 now i am in process of changing the database connection part. As part of the process i have a login authorization code. Private Function Authenticate(ByVal username As String, ByVal password As String, ByRef results As NorisSetupLib.AuthorizationResult) As Boolean Dim conn As IDbConnection = GetConnection() Try Dim cmd As IDbCommand = conn.CreateCommand() Dim sql As String = "EDSConfirmUpdate" '"EDSConfirmUpdate""PswdConfirmation" 'Dim cmd As SqlCommand = New SqlCommand("sql", conn)
cmd.CommandText = sql cmd.CommandType = CommandType.StoredProcedure NorisHelpers.DBHelpers.AddParam(cmd, "@logon", username) NorisHelpers.DBHelpers.AddParam(cmd, "@password", password) conn.Open() 'Get string for return values Dim ReturnValue As String = cmd.ExecuteScalar.ToString 'Split string into array Dim Values() As String = ReturnValue.Split(";~".ToCharArray) 'If the return code is CONTINUE, all is well. Otherwise, collect the 'reason why the result failed and let the user know If Values(0) = "CONTINUE" Then Return True Else results.Result = Values(0) 'Make sure there is a message being returned If Values.Length > 1 Then results.Message = Values(2) End If Return False End If Catch ex As Exception Throw ex Finally If (Not conn Is Nothing AndAlso conn.State = ConnectionState.Open) Then conn.Close() End If End Try End Function ''' ----------------------------------------------------------------------------- ''' <summary> ''' Getting the Connection from the config file ''' </summary> ''' <returns>A connection object</returns> ''' <remarks> ''' This is the same for all of the data classes. ''' Reads a specific connection string from the web.config file for the service, creates a connection object and returns it as an IDbConnection. ''' </remarks> ''' ----------------------------------------------------------------------------- Private Function GetConnection() As IDbConnection 'Dim conn As IDbConnection = New System.Data.OleDb.OleDbConnection Dim conn As IDbConnection = New System.Data.SqlClient.SqlConnection conn.ConnectionString = NorisHelpers.DBHelpers.GetConnectionString(NorisHelpers.DBHelpers.COMMON) Return conn End Function in the above GetConnection() method i have commented out the .net dataprovider for oledb and changed it to .net dataprovider for SQLconnection. this function works fine. But in the authenticate method above at the line Dim ReturnValue As String = cmd.ExecuteScalar.ToString
for some reason its throwing the below error. Run-time exception thrown : System.Data.SqlClient.SqlException - @password is not a parameter for procedure EDSConfirmUpdate. If i comment out the Dim conn As IDbConnection = New System.Data.SqlClient.SqlConnection and uncomment the .net oledb provider, Dim conn As IDbConnection = New System.Data.OleDb.OleDbConnection then it works fine. I also have changed the webconfig file as below. <!--<add key="Common" value='User ID=**secret**;pwd=**secret**;Data Source="ESMALLDB2K";Initial Catalog=cj_common;Auto Translate=True;Persist Security Info=False;Provider="SQLOLEDB.1";' />--> <add key="Common" value='User ID=**secret**;pwd=**secret**;Data Source="ESMALLDB2K";Initial Catalog=cj_common;' />
I have a replication log reader SPID hanging. When the logreader tries to run again, it fails due to Error 14151 Replication log reader - task "blah" failed. Another log reader is replicating the database.
I do a sp_who2 on the database and identify the spid that is running the logreader, from here I usually kill the spid and the log starts up again no problem. Now the spid WON"T DIE!!! Any help would be appreciated. Thanks Susan
We are planing to write a script that execute frequently to kill processes that are running for more than 1 minute. Does anyone knows the logic to filter out system or other required SQL processes from this auto kill script
I have SQL Server 7.0 with SP2 on it and I am not able to kill one of the SPID's who is running a SELECT Statement. When I saw in the current activity in EM I see the STATUS as ROLLBACK, COMMAND as SELECT, APPLICATION as MS SQLEM-DATATOOLS, WAITTIME as 5375 and WAITTYPE as CXPACKET..
I also tried to reboot the machine of that particular SPID , but it still shows up in the Enterprise Manager.
Can anyone tell me how to kill this process and how to get around this Problem
How to kill process??? I turn off workstation but the process still available in the sysprocesses table and in the Curent activity window. I can't to kill this (and I can't to restart serever, because the users) .
If anyone know something about this problem. Thanks
Does anyone have a script for killing transactions older than 24 hrs? I have been having problems with users bootting out and leaving open transactions, I'd like to clean up all the orphans early every morning.
I am trying a WHILE on DBCC OPENTRAN.
We are using TCP/IP sockets, apparently they never notify the db server that the user has dropped, sockets stay open by default.
/* The Following Stored Procedure helps to Kill All Processes in a Particular DataBase With Out Current Process */
Create Proc Sp_KillAllProcessInDB
@DbName VarChar(100)
as if db_id(@DbName) = Null begin Print 'DataBase dose not Exist' end else
Begin Declare @spId Varchar(30)
DECLARE TmpCursor CURSOR FOR Select 'Kill ' + convert(Varchar, spid) as spId from master..SysProcesses where db_Name(dbID) = @DbName and spId <> @@SpId and spId > 50 and dbID <> 0 OPEN TmpCursor
FETCH NEXT FROM TmpCursor INTO @spId
WHILE @@FETCH_STATUS = 0
BEGIN
Exec (@spId)
FETCH NEXT FROM TmpCursor INTO @spId
END
CLOSE TmpCursor DEALLOCATE TmpCursor
end /* The Above Query Helps TO Change a Database in Single USer Mode Quickly*/
I have been needing to disconnect users often, before backing up a database or setting it to restricted users. Each time, I have to go to Current Activity & kill one process at a time. Is there a way, by which I can kill all processes on a database or force out all coonections to it?
Hi! After I killed maintenance process (57) in the current activity window and run ‘kill 57 with statusonly’ I got message: ‘SPID 57: Estimated rollback completion: 100%. Estimated time remaining: 0 sec.’ When I reopened current activity window I still see that SPID 57 is runable. Then I run select*from sysprocesses where SPID = 57 It also reports that process status is runable. What is the problem? How can I remove (and should I) this record from masterdb. Thank you, Natalia
Im just a newbie using SQL Server anyway i noticed in my present company that most of the process/Stored Procedure that are being executed or connection that was being made by the application is not being terminated or disconnected. they use very large IO and CPU resources making the server slow or sometimes hang.(well that was my diagnostics). i try to kill them one by one but it seems endless process is redundant. to cut my problem short im thinking of having an application that would automatically kill all this unwanted process but ofcourse i should specify the parameter which process to kill. is this possible? i saw the KILL statement in the online books but it seems uncomplete with what i wanted to accomplish.
Im just a newbie using SQL Server anyway i noticed in my present company that most of the process/Stored Procedure that are being executed or connection that was being made by the application is not being terminated or disconnected. they use very large IO and CPU resources making the server slow or sometimes hang.(well that was my diagnostics). i try to kill them one by one but it seems endless process is redundant. to cut my problem short im thinking of having an application that would automatically kill all this unwanted process but ofcourse i should specify the parameter which process to kill. is this possible? i saw the KILL statement in the online books but it seems uncomplete with what i wanted to accomplish.
Can you kill processes in SQL Server 2K without stopping SQL Server and restarting it? I am using sp_who2 to get a list of active users and I see some accounts that are logged off but still showing up and I am trying to find a way to Kill these accounts and the processes they are doing.
Hello,I do maintenance on the Back endand have like 10 - 20 connections open...specialized scrips i run and theydont need to be stored proc'sis there a way to kill the connection when the script is finished...from myclient side.....not just disconnect...cause server still has the pool of the connection...iwant to kill the pool'd connection alsothanksDave P
I build the sql beautifully to call it with Openquery
"select * from OPENQUERY(MYLink,'DECLARE P_DATE VARCHAR2(20); BEGIN P_DATE := ''15-Sep-2006 17:26:09''; EXEC poPT (P_DATE); COMMIT; End;')
"Server: Msg 7357, Level 16, State 2, Line 1"
"Could not process object 'DECLARE P_DATE VARCHAR2(20); BEGIN P_DATE := '15-Sep-2006 17:26:09'; EXEC poPT(P_DATE); COMMIT; End;'. The OLE DB provider 'MSDAORA' indicates that the object has no columns."
I cannot seem to find away to make this work.
I wanted to return just the record count to make it happy but that did not work either.
The linked server is fine, the grants are fine.
I even tried this as a function in oracle to no avail.
I feel like I am going insane trying to make something that SHOULD BE SIMPLE work.
It's times like this that you really appreciate SQL Server....
Hi, Could anyone tell me why I am not able to kill processes even with kill spid. I had scheduled some db backups through DB Maintenance. All of them are running for days together when I tried to kill them spid. It still does not get killed. Can anyone tell me why
I have SQL Server 7.0 and I am not able to kill one of the SPID's who is running a SELECT Statement and showing as sleeping. When I saw in the current activity in EM I see the STATUS as sleeping COMMAND as SELECT, APPLICATION as Microsoft Transaction server, WAITTIME as 7877 and WAITTYPE as EXCHANGE and CPU 10074 Thanks in advance.
I'm having a problem killing a process in SQL 7.0. I have a spid that has been around for a couple of weeks! I try to remove that process by right clicking and selecting 'Kill Process' but nothing happens. The process originated when I deleted large amounts of data from a logging table. NOw I can not remove the process. I'm concerned that this might indicate the database is getting corrupted. Any suggestions?
Forgive me for what may be a dumb question but i`m having trouble using the kill statement in a stored procedure. The problem is that i always get a syntax error when using the kill statement with a local variable as the parameter. For example some part of the code is: declare @myspid smallint ... exec kill @myspid ...
I have a user who is Business owner of a database that is transactional.
At times some of here staff will be the leadblocker.
She has requested that she be allowed the abiity to KILL spids that are blocking her remaining users. All have blessed this process and I havve been tasked to create a way for this to be accomplished.
Is this as simple as allowing this user a permission or is it more in depth.