API Server Cursors - SQL Server Sessions
Nov 8, 2004
While analyzing Process/Session Information in SQL Server Current Activity over the last several months on our ERP's SQL Server I have noticed that the number of sessions open starts at a very low number after a system reboot (150), then slowly grows as users login and system activity increases. This seems very normal, except that over the next few weeks the number slowly increases (3500) until we reboot.
After looking at the sessions closely many of them have login times and last batch times that are the same, which tells me that a connection was made, but nothing has really happened since. For example, many of the sessions were opened 5 days ago and the last batch run by these sessions were 5 days ago too. Most of them are have a last SQL command batch ran as “sp_cursorclose;1”, ”sp_cursorunprepare;1”, or ”sp_cursorexecute;1”.
Performance definitely degrades over time as the number of sessions increases, until we reboot. Also, you would expect to see this number of sessions decrease during slow times, but this does not occur. Could something be mistakenly leaving connections open?
SQL Server 2000 sp3
Windows Server 2000 sp3
ERP - PeopleSoft EnterpriseOne XE
View 3 Replies
ADVERTISEMENT
Jan 19, 2007
hi all
i am using .net web application with sql server as my database, i want to login by authentication from my database which i ave done but now i want to add session but dont know the code so if anyone can help me with stepwise process to assign username in the seeion also to create and destroy the session.urgent help required
View 1 Replies
View Related
Mar 13, 2001
How can many users share the same .adp front end, just like it as if it was a .mdb file? The problem I've ran was the following...user A logs in, user B tries to use the same .adp front end, but gets a message that is already in use therefore can't get in. Thanks in advance!
View 1 Replies
View Related
Feb 2, 2015
Is there a way to find the max number of sessions that were on a sql server since its last restart? I know how to get how many total connections there were since last restart, and the current number of sessions, but not the max number of sessions that were running since last restart. Also, opinion on the optinum number of allowable sessions, or a good way to figure out the balance?
View 0 Replies
View Related
Feb 9, 2006
Hi,
Can you help me how to find out sessions in SQL Server 2000.
Also is there any way to see the outstanding sessions for a database?
Thanks in advance,
Vasu.
View 4 Replies
View Related
Jun 29, 2015
We have a big software that run a warehouse distribution center, written in .NET Backhand is a SQL Server 2008 R2 STD database.
Now, it seems there is a problem with the sessions not being properly closed after each call to the DB. Here is the message got form SQL:
DESCRIPTION:A new connection was rejected because the maximum number of connections on session ID 57 has been reached. Close an existing connection on this session and retry.
In the .NET code, connection is made with the following code:
If oConn Is Nothing Then oConn = New SqlConnection
If oConn.State = ConnectionState.Open Then oConn.Close()
With oConn
.ConnectionString = "Server=" & Server & ";Database=" & DB & ";User ID=" & User & ";Password=" & Pass & ";Connection Timeout=" & 5 & ";MultipleActiveResultSets=" & True
.Open()
End With
This code is called once, at the opening of the software
StoredProc are call with the code:
Try
oCmd = New SqlCommand
With oCmd
.Connection = oConn
.CommandType = CommandType.StoredProcedure
[Code] .....
So every Command is closed after execution, yet, they stay active in the SQL Server. Is there something I'm missing here?
View 3 Replies
View Related
Apr 4, 2001
I am looking for an example of how to navigate N records at a time using Server side cursors in SQL Server and ASP. I immagine I have to declare cursors, fetch rows, etc. but I would like to see a specific example. Does anybody know where I can find this information or maybe provide me with an example? Thanks for the help, I am a bit lost with this.
View 2 Replies
View Related
Apr 7, 2008
Hi,
I'm migrating an Application from .net / oracle to .net / sql server express
In the Oracle DB, there are several Stored Procedures that return cursors that are thrown into DataSets in the application.
I'm converting the Data Access Layer class right now and I realized in this line of code:cmd.Parameters.Add(New SqlParameter("csr_out", OracleType.Cursor)).Direction = ParameterDirection.Output
that there is no
cmd.Parameters.Add(New SqlParameter("csr_out", SqlDbType.Cursor)).Direction = ParameterDirection.Output ???
What would be the equivalent of retrieving an Oracle cursor into a DataSet using SQL Server ?
Thanks
View 4 Replies
View Related
Nov 14, 2005
I have read ample technical papers on Cursors. I like to use cursors because it gives you a row by row control in a stored procedure. But most articles I have read advise against the use of cursors (server side).I typically use read only or Forward Only Cursors. This seems to be the best way to transpose data.My questions is, is there any guildlines to using cursors? Do you look at the performance of the cursor? If the query runs in 30 seconds and the cursor process is 15 seconds, is that acceptable (based on a million transactions, but filtering 1000-2000 records based on indexed fields.)?Or is it better to break cursor based steps into multiple queries with insert / update to generate a transposed output? Even if this involves a base query with multiple joins. Is it better to hammer SQL Server once and then output the results on a row by row, column by column basis, or do multiple queries.The bottom line is I have been able to provide the required output using cursors, but I just don't want to potentially bog down the system.Can anyone list specific cases where a cursor was a better method than multiple queries? And particularily with large volume data mining operations. Thanks DotNetNow
View 5 Replies
View Related
Jun 23, 2006
Hi Everyone!We are using a cursor for paging results in SQL server, mainly due tothe performance gains achieved when working with large results sets.We have found this to be of great benefit when working with SQL Server2000, but have run into major problems when using it on SQL Server2005.The query goes like this:DECLARE @PageSize intSET @PageSize = 10DECLARE @PK intDECLARE @tblPK TABLE (PK int NOT NULL PRIMARY KEY)DECLARE PagingCursor CURSOR DYNAMIC READ_ONLY FORSELECT KeyID FROM JobTable WHERE KeyID IN(SELECT KeyID FROM JobTableWHERE Criteria = TRUE) ORDER BY JobTable.KeyIDOPEN PagingCursorFETCH RELATIVE 1 FROM PagingCursor INTO @PKSET NOCOUNT ONWHILE @PageSize > 0 AND @@FETCH_STATUS = 0BEGININSERT @tblPK (PK) VALUES (@PK)FETCH NEXT FROM PagingCursor INTO @PKSET @PageSize = @PageSize - 1ENDCLOSE PagingCursorDEALLOCATE PagingCursorSELECT ResultsFields FROM JobTable INNER JOIN @tblPK tblPK ONJobTable.KeyID = tblPK.PK WHERE Criteria = TRUE ORDER BYJobTable.KeyIDI know this doesn't look as optimised as it should but there is a lothappening under the hood to get it to this point. This aside, theremust be a reason why performance suffers so much with SQL 2005?Inserting a print statement into the cursor loop outputting the datestamp showed that each iteration was taking approx 4.5 seconds. Thisis a problem we never experienced in SQL Server 2000.Any help would be greatly appreciated!Thanks in advance,Steve
View 1 Replies
View Related
Jun 2, 2006
Are cursors still taboo, performance killers in SQL Server 2005. If not, how has the behavior changed?
View 3 Replies
View Related
Jan 22, 2015
I have a table with the following columns employeeSessionID, OpDate, OpHour, sessionStartTime, sessionCloseTime. I need to see how many users remain active per hour. I can calculate how many logged in per hour, but I am stumped on how to count how many are active per hour. I have a single table that stores login data. I have created a query that pulls out the only the data needed from the table into a temp table using this query. Also note it is possible that the sessionCloseTime is null if the device has not been logged out this would need to be counted a active.
TABLE NAME #empSessionLog Contains the time stamp data OpDate, sessionStartTime and sessionCloseTime.
OpDatesessionStartTimesessionCloseTime
2015-01-202015-01-20 14:32:59.1302015-01-20 14:33:14.6299166
2015-01-202015-01-20 06:58:33.7302015-01-20 15:27:16.9133442
2015-01-202015-01-20 09:56:22.8402015-01-20 17:56:29.7555853
2015-01-202015-01-20 05:59:18.6132015-01-20 14:05:19.0426707
[code]....
can see how many sessions logged in per hour with the following statement:
SELECT
opDate,
FORMAT(DATEPART(HOUR, sessionStartTime), '00') AS opHour,
Count(*) AS Total
FROM #empSessionLog
Group BY opDate, FORMAT(DATEPART(HOUR, sessionStartTime), '00')
Order BY opDate, FORMAT(DATEPART(HOUR, sessionStartTime), '00') ASCResults:
opDateopHourTotal
2015-01-20041
[code]....
Where I am stuck is how do I count the sessions that remain active per hour until the session is closed with the sessionCloseTime.
View 5 Replies
View Related
Apr 10, 2015
I created am inventory table with few columns say, Servername, version, patching details, etc
I want a tracking of the table.
Let's say people are asked to modify the base table and I want a complete capture of the details modified and the session of the user ( ) who (system_user) is actually modifying the details.
View 1 Replies
View Related
Nov 29, 2006
I am trying to simplify a query given to me by one of my collegues written using the query designer of Access. Looking at the query there seem to be some syntax differences, so to see if this was the case I thought I would import the database to my SQL Server Developer edition.
I tried to start the wizard from within SQL Server Management Studio Express as shown in one of the articles on MSDN which did not work, but the manual method also suggested did work.
Trouble is that it gets most of the way through the import until it spews forth the following error messages:
- Prepare for Execute (Error)
Messages
Error 0xc0202009: {332B4EB1-AF51-4FFF-A3C9-3AEE594FCB11}: An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft JET Database Engine" Hresult: 0x80004005 Description: "Could not start session. Too many sessions already active.".
(SQL Server Import and Export Wizard)
Error 0xc020801c: Data Flow Task: The AcquireConnection method call to the connection manager "SourceConnectionOLEDB" failed with error code 0xC0202009.
(SQL Server Import and Export Wizard)
Error 0xc004701a: Data Flow Task: component "Source 33 - ATable" (2065) failed the pre-execute phase and returned error code 0xC020801C.
(SQL Server Import and Export Wizard).
There does not seem to be any method of specifying a number of sessions, so I don't see how to get round the problem.
Does anyone know how I can get the import to work?
View 2 Replies
View Related
Oct 14, 2004
Hi,
Has anybody had any luck using the Microsoft SQLServer ODBC drivers (Driver version: 03.81.9030, ODBC version : 03.52)
to connect to a SQL Server 2000 database and passing in a SELECT with a FOR XML clause. I keep
getting Error [Microsoft][ODBC SQL Server Driver][SQL Server]The FOR XML clause is not allowed in a CURSOR statement
., State: 42000, Error: 6819.
Is there a work around (eg putting the select in a stored procedure) or am I missing something ?
I am using SQLExecDirect() to execute the statement.
Or could any one suggest a better way to retrieve data from a standard table in XML formated string?
Please Help!!
View 1 Replies
View Related
Jan 13, 2008
Hi,
I've the following program structure:
For every record
-- insert into table1
-- insert into table2
....
if I encounter an error in the table1 insert, is there any way (other than using cursors) to continue processing the next record?
Thanks for your help.
Subha Fernando
View 11 Replies
View Related
Jul 13, 2004
As part of a nightly process, I must call a stored procedure that uses cursors to update a Sybase linked server from SQL Server. The stored proc was written by someone else and is intended to interface to a finance system to upload new transactions.
The stored proc works fine most of the time but occasionally dies part-way through with the following confusing error message:
[OLE/DB provider returned message: Internally generated command failed to affect a row.]
OLE DB error trace [OLE/DB Provider 'Sybase.ASEOLEDBProvider' IRowsetChange::SetData returned 0x80004005: ].
Msg 7399, Level 16, State 1, Server ********, Procedure ********, Line 162
OLE DB provider 'Sybase.ASEOLEDBProvider' reported an error.
I initially ran this stored proc from a perl script via an ODBC link but in the futile hope of fixing this problem I tried manually executing it via isql.exe instead. Both return exactly the same error. I have also increased the OLE/DB query timeout to 15 minutes with no success in stopping the problem.
There seems to be no connection I can spot between when it succeeds and when it fails. When scheduled to run just after midnight it fails about 30% of the time (at a time when there should be a light load on the servers). When run manually it almost always suceeds (I have only managed to get it to fail through running manually once in dozens of attempts).
I can't seem to find anything relevant about this error via Google or any of my usual reference sources so hoped someone else might have a clue as to what the hell's going on. :confused:
The stored procedure uses a cursor to traverse a SELECT statement then performs several INSERTs, UPDATEs and DELETEs depending upon each row processed and attempts (but usually fails) to perform a ROLLBACK upon an error.
I'd appreciate any pointers in the right direction here. Is it because I'm performing cursor-based operations on a linked server? Is it due to the linked server being a Sybase server? Could it be due to locking problems or timeouts? Is my server in a bad mood and simply trying to taunt me? I'm tearing my hair out trying to find more information on this annoyingly intermittent problem and really appreciate any help or tales of similar errors.
Thanks in advance
View 11 Replies
View Related
Sep 20, 2007
Problem:
Two tables t1 and t2 have the same schema but exist on two different servers. Which is the better technique for updating t2 and why?
/****** Object: Table [dbo].[t1] Script Date: 9/6/2007 9:55:21 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[t1]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[t1]
GO
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[t1]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[t1] (
k [int] IDENTITY (1, 1) NOT NULL ,
a [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
b [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
c [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
x [int] NULL ,
y [int] NULL ,
amt [money] NULL
) ON [PRIMARY]
END
GO
/****** Object: Table [dbo].[t2] Script Date: 9/6/2007 9:55:44 AM ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[t2]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[t2]
GO
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[t2]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[t2] (
k [int] IDENTITY (1, 1) NOT NULL ,
a [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
b [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
c [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
x [int] NULL ,
y [int] NULL ,
amt [money] NULL
) ON [PRIMARY]
END
GO
-- Technique 1:
set identity_insert t2 on
insert into t2 (k,a,b,c,x,y,amt)
select k,a,b,c,x,y,amt from t1
where not exists (select k from t2 where t1.k = t2.k)
set identity_insert t2 off
update t2
set a = t1.a,
b = t1.b,
c = t1.c,
x = t1.x,
y = t1.y,
amt = t1.amt
from t1
where t1.k = t2.k
-- Technique 2:
set identity_insert t2 on
declare t1_cur cursor for
select k,a,b,c,x,y,amt from t1
for read only
open t1_cur
declare @k int
declare @a char(10)
declare @b char(10)
declare @c char(10)
declare @x int
declare @y int
declare @amt money
fetch next from t1_cur into @k,@a,@b,@c,@x,@y,@amt
while(@@FETCH_STATUS = 0)
begin
if exists(select k from t2 where k = @k)
begin
update t2
set a = @a, b = @b, c = @c, x = @x, y = @y, amt = @amt
where (k = @k)
end
else
begin
insert into t2 (k,a,b,c,x,y,amt) values(@k,@a,@b,@c,@x,@y,@amt)
end
fetch next from t1_cur into @k,@a,@b,@c,@x,@y,@amt
end
close t1_cur
deallocate t1_cur
set identity_insert t2 off
Thanks,
Joel K
Database Adminstration/Application Development
View 1 Replies
View Related
Sep 20, 2015
I have basic knowledge of T-SQL and I am using Cursors to get the first value, the last value and the peak value and some other values from other tables. I found some examples on google but the code I am using is mixed up. I am using multiple Cursors. I need to join three tables to get the result set into the Cursor. The first example uses 2 tables.
@FirstName NVARCHAR,
@LastName NVARCHAR,
@FirstValue decimal,
@HighestValue decimal,
@LastValue decimal
-- First Cursor
DECLARE TESTCURSOR CURSOR
DYNAMIC
[Code] ....
The above code seems totally inefficient but it gives the correct result. Now I want to pull some more value and join a third table (TABLE z) in the above CURSORS and not sure how to make it working using CURSORS.I would like to use the following in the CURSORS above.
SELECT x.publishdate, y.firstname, y.lastname, y.age, z.initialValue AS FirstValue, z.HighestValue AS Highest, z.LastValue AS Last
FROM TABLE x
LEFT OUTER JOIN TABLE y
ON x.id = y.id
INNER JOIN TABLE z
ON x.id = z.id
View 9 Replies
View Related
Jun 25, 2015
fix the below SP which is having cursor output with an alternate logic which can make the SP work.(may be using temp table or any other option)
CREATE PROCEDURE Get_IDS
/*
* SSMA warning messages:
* O2SS0356: Conversion from NUMBER datatype can cause data loss.
*/
@p_uid float(53),
@return_value_argument varchar(8000) OUTPUT
[code]....
View 1 Replies
View Related
Jul 30, 2006
Hi,
Here is my code on how i connect to my database
Dim rst As New ADODB.Recordset Dim conn As New ADODB.Connection Dim vresponse As String ' On Error GoTo err_proc Try conn.Open(GetConn(getconnid)) Select Case getmode Case 0 'execute then return first field rst = conn.Execute(getsql) If rst.EOF = False And rst.BOF = False Then Try vresponse = IIf(IsDBNull(rst.Fields.Item(0).Value), "", rst.Fields.Item(0).Value) ' vresponse = rst.Fields.Count Catch ex As Exception vresponse = "Error :" + ex.Message End Try End If Case 1 'execute only If bTransactional = True Then conn.BeginTrans() End If conn.Execute(getsql) vresponse = "OK" If bTransactional = True Then conn.CommitTrans() End If End Select
Return vresponse.Trim
* line 1)
rst = Nothing conn = Nothing
Exit Function
supposed to be *line 1) terminates the connection/session form SQL server. But when i check to the SQL Query Analyzer, there is still some connections related to this command. So when i run again this commands, it creates another connection. How can i terminate/end my sessions in SQL.
Thanks
View 1 Replies
View Related
Jan 12, 2000
Hi all!
First of all, thanks to those who gave me suggestions to use sql-dmo
to generate sql scripts of a database.
I've found it extremely useful!
Here's my new problem.
I have VB code that connects to a database, extracts the schema
and generates the sql.
After some work with this script, I have some new scripts to alter the database and I have tried running these scripts in a separate project
with the ExecuteImmediate method of the Database object, which works well.
However, when I put this code into the first project, to reconnect to the database and execute the batch command,
I get SQL-DMO error -2147199229 (80045203)
...whatever that means..
Can anyone help me?
Thanks
View 1 Replies
View Related
Feb 27, 2008
Hi Friends,
We need a small suggestion regarding releasing the resources utilized before closing the session we established with the SQL CE database. To the best of our knowledge we are releasing the resources properly but still some how some resources get locked and we were not able to open a new session after closing the existing session.
Are there any functions or methods available to identify the existing resources, rowsets and other components who have connection with the existing session, kindly help us in this regard since we struck up mainly with this issue.
We work with EVC++ 3.0 and SQL CE 2.0
Thanks in advance.
Regards,
Sasi.
View 2 Replies
View Related
Apr 25, 2008
hi is it possible to insert a session into a database E.G. i'm sure this code is fine but i duno why its not inserting the session into the database the form parameter is going in fine but the session aian't
UserName.Text = Session("User")<asp:sqldatasource id="SqlDataSource1" runat="server"
selectcommand="SELECT Party.Party FROM Party"
insertcommand="INSERT INTO Vote(UserName,Vote) VALUES (User,Party)"
ConnectionString="<%$ ConnectionStrings:VotingConnectionString %>"
ProviderName="<%$ ConnectionStrings:VotingConnectionString.ProviderName %>">
<InsertParameters>
<asp:SessionParameter Name="User" Type="String" SessionField="User" />
<asp:FormParameter Name="Party" Type="String" FormField="PartyList" />
</InsertParameters>
</asp:sqldatasource>
View 7 Replies
View Related
May 19, 2008
I have a process that seems to leave many orphaned sessions over a period of time. The software is by a 3rd party vendor and they can't seem to fix it. It is safe to end the orphaned sessions and I do that on a regular basis. My questions is: What is the best way to do this via T-SQL?
I can select the orphaned sessions by using a simple query on the sys.dm_exec_sessions table. How do I then run a kill command for each session_id from that query?
I appreciate any info/advice anyone might have!
View 5 Replies
View Related
Sep 6, 2006
Hey
I have a problem in controlling the report session.
I created a Reporting Model using SQL reporting Services 2005 with Forms authentication on which I implemented the security Filter based on the function GetUserID() to report only against data that belong to the login User, and I deployed the Model.
Using report Builder application I created a report that contain in the first column the user name (UserName) from entity €œUsers€?, and in the remaining columns data from other entities related to table users, I saved the report on the report server.
I logged in into report manager with user €œUser1€? and I ran the report, the result was the same as expected (in the first column €œUser1€? appeared and in the remaining column other data related to this user appeared) every thing went good
After that I logged in with the user €œUser2€? and I ran the report and here was the surprise the same data that appeared for "User1" appeared for "User2". but what was Expected is different data that belong to "User 2"
After some research that says that this problem may be caused by a session issue (the session created for the first user who enters the report server will remain for the other users that enter after him), I reset IIS and I logged in with €œUser2€?, and I ran the report the correct data for €œUser2€? appeared So it may be a session issue.
My question is:
Is there any way to control the session content and the session expiration?
Please note I used all the solution provided in my research such as URL parameter rs:ClearSession = true, and the Report Execution Options in report manager but non of this helped me.
I will be thankful for any one who could help me in this urgent issue.
Thank you
BOB
View 3 Replies
View Related
Mar 16, 2004
I'm using SQL server 7 on Win NT. I have Access 97 as a front end, with linked tables though ODBC to SQL Server. Everytime I open a table in Access, a session appears when I type sp_who2. I close that table in Access, but I when I type sp_who2 the table session is still present. Does anyone know a cause for this?
I am researching why sometimes when we close are queries and tables in Access we have sessions in SQL server that becomes orphans/ghost. I try to kill the session but can't, so therefore I have to recycle the database.
Any help would be appreciated.
View 2 Replies
View Related
Aug 29, 2011
When I probe sys.dm_exec_sessions (joining with other DMVs to get active-session info) I get the login_name column to be blank for a certain session.
Yet, for the same spid, the Login shows up properly (not blank) when I execute "sp_who2 active".
It also shows up properly in sys.sysprocesses.
What could be the reason for the faulty output of sys.dm_exec_sessions ?
View 9 Replies
View Related
Feb 15, 2008
I just have a simple question on font dependencies in reference to deployed reports. In my company, we run citrix presentation servers feeding terminal sessions out to users in remote areas.
My question is, in a terminal session, do the fonts used in the reports need to be installed on the users' local machine (who is connecting via terminal session) or is it enough to just have it on the servers feeding out the terminal session?
For example, we create a report with Arial Narrow font. Our servers hosting citrix presentation server did not have this font installed, so we installed this font on the servers (thus they're displaying correctly). Obviously the server hosting our reporting services has the font. Now a user connects to the server, is granted a terminal session, launches reporting services, report is generated with the correct font displayed, and finally prints the report.
Will the report print in Arial Narrow if the users' local machine doesn't have this font install? I remember reading somewhere that the fonts do not embed, hence the reason for installing the font on our citrix servers.
I realize this is kinda out of the scope of this forum, but perhaps someone on here uses terminal services and can answer this for me. I do plan to test this out when I get home tonight. I'd test it right now, but my computer at home isn't on therefore I can't remote home (plus wake-on-lan isn't configured) to do an actual test. Just thought I'd get some insights from other people.
Thanks in advance!
View 3 Replies
View Related
Apr 6, 2006
Hi
I have been looking at the new DMV's prefixed with dm_exec_....and found a limitation with them.
Books online says sysprocesses is replaced with sys.dm_exec_connections, sys.dm_exec_requests and sys.dm_exec_sessions. The problem I came accross is identifying any sessions connected to a specific database which were idle. This is the sort of thing you need to know if you tried to restore a database and it says the database is in use.
I wonder if this is a bug or by design?
View 8 Replies
View Related
Mar 8, 2015
So I've been monitoring long-running transactions on a SQL Server that hosts a couple of vendor-supplied databases that look after our factory.Today I noticed a pair that have confused my Excel spreadsheet (that I've been using to analyze these transactions).So here's the weird thing that I spotted. Given this query:
SELECT p.spid, p.login_time, at.transaction_begin_time, datediff(second, p.login_time, at.transaction_begin_time) as [difference]
FROM sys.sysprocesses AS p INNER JOIN
sys.dm_tran_session_transactions AS st ON st.session_id = p.spid INNER JOIN
sys.dm_tran_active_transactions AS at ON st.transaction_id = at.transaction_id
[code]....
I had a look in the event log on the server, which had just been rebooted at around that time. It seems that the clock got changed on boot-up, with the size of it quite surprising. This meant that these processes were able to start their transactions *before* they logged on. Hopefully this doesn't cause any other weird problems.So I've requested an investigation about time synchronization on our virtualization hosts... and in the mean time, have set the SQL Server services to 'delayed start'.
View 0 Replies
View Related
Jul 23, 2005
I have a table EugeneTest(id_num, fname, minit, lname)where field "id_num" is type IDENTITY and has UNIQUE constraintLet's say 2 user execute this code at the same time:DECLARE @return integeruse EugeneTestINSERT employees( fname, minit, lname)VALUES( 'Eugene3', 'F', 'Josephs')SET @return = @@IDENTITYIs is not possible to get duplicated value in id_num column becuase ofUNIQUEconstraint, but is it possible the both user get the same @@IDENTITYnumber( for example, if @@IDENTITY is evaluated and kept somewhere in thebuffer before the data actually get written to the disk )Thanks, Eugene
View 5 Replies
View Related
Nov 21, 2015
The benifit of UPDLOCK is that it avoids deadlock in case both sessions run the below query at the same time.The table has clustered index on ID column
----session 1 --------
begin transaction
select * from a1
update a1
set id = 22
where id = 2
----session 2 --------
begin transaction
select * from a1
update a1
set id = 22
where id = 2
Now to avoid deadlock in the above scenario we should use (UPDLOCK) hint in the select statement.Now my question is that deadlock will be avoided in this case when both the sessions use UPDLOCK hint. If only one session uses UPDLOCk and other does not then there will be deadlock .For example session 1 uses UPDLOCK hint this will hold the U lock on the row, but the session 2 does not use this hint and apply shared lock on the same row. Now there will be deadlock when session 1 tries to update the record and is blocked by shared locks of session 2. same will be the case with session 2 and both will wait for each other and hence dead lock.so what steps can be taken to avoid deadlocks in this case. I do not want to use Snapshot isolation.
View 3 Replies
View Related