For performance issue, I believe many program should have a house-keeping procedure to clean up transaction history. Is there any best practice to perform this? Or should it be done simply by moving transaction data from the transaction table into a history table? Any better or consideration that I should be concerned of?
I have over 500 transaction records in a single DB process handling within SQL transaction (Begin, Commit, RollBack and End). Is there any limitation for the following rollbacktransaction function to handle more records (eg. over 500 records)? Public Shared Sub RollBackTransaction() Dim transactionObj As Object Try transactionObj = SqlTransaction.GetExistingTransaction If (Not IsNothing(transactionObj)) Then CType(transactionObj, SqlTransaction).RollBack() End If
Catch ex As Exception Throw New Exception(ex.Message) End Try End Sub
I like to put a set of sql statements under a transaction and wish the sql server to take care of commit / roll back the entire set depending upon the success/failure of the statements in the set. I want the whole set is either to success or to failure.
When I go through the docs, i find that SQL Server 2000 operates three transaction modes: Autocommit transactions : Each individual statement is a transaction.
Explicit transactions : Each transaction is explicitly started with the BEGIN TRANSACTION statement and explicitly ended with a COMMIT or ROLLBACK statement.
Implicit transactions: A new transaction is implicitly started when the prior transaction completes, but each transaction is explicitly completed with a COMMIT or ROLLBACK statement.
As one can see, it seems that it is not possible to define "atomic compound sql statements". Even if i used explicit transaction, it is not possible to achieve this, since i couldn't find a mechanism to handle errors for a group of statements.
I wonder how to write atomic compound sql statement in the sql server. can anybody please help me on this....
Hi all i am using Vs 2005 for Web application Development. At one place i have to update 2 tables and i have to insert in 1 table.For that i am using following function. But i am getting error pls help me. My function is. Public Function UpdateItemDetails(ByVal executemode As ExecuteMode, ByVal Remarks As String, ByVal userid As String, ByVal ItemDetails As ArrayList, ByVal rfsno As String, ByVal rfsstatus As String) As Integer Try Dim sql As String Dim con As New SqlConnection(conString) con.Open() cmd.Connection = con trans = con.BeginTransaction() cmd.Transaction = trans ''Updating TSMS_RFSITEMDETAILS Table.For Each acc As item1 In ItemDetails Dim Itemid As String = acc.INameDim quantity As String = acc.QUANTITY Dim Total As String = acc.TOTAL sql = "update " + tabPrefix + "RFSITEMDETAILS set QUANTITY=@QUANTITY,TOTAL=@TOTAL,REMARKS=@REMARKS where ITEM_ID=@ITEM_ID"cmd.Parameters.Add("QUANTITY", SqlDbType.NVarChar, 50).Value = acc.QUANTITY cmd.Parameters.Add("TOTAL", SqlDbType.NVarChar, 255).Value = acc.TOTALcmd.Parameters.Add("ITEM_ID", SqlDbType.Int, 10).Value = acc.INamecmd.Parameters.Add("REMARKS", SqlDbType.NVarChar, 50).Value = Remarks cmd.CommandType = CommandType.Text cmd.CommandText = sql cmd.ExecuteNonQuery()Next ''Updating TSMS_RFS Table. sql = "update " + tabPrefix + "RFS SET RFS_STATUS=@RFS_STATUS,UPDATEDBY=@UPDATEDBY where RFS_NO=@RFS_NO" cmd.Connection = concmd.Parameters.Add("RFS_STATUS", SqlDbType.Int, 50).Value = rfsstatus cmd.Parameters.Add("RFS_NO", SqlDbType.NVarChar, 10).Value = rfsnocmd.Parameters.Add("UPDATEDBY", SqlDbType.Int, 50).Value = userid cmd.CommandType = CommandType.Text cmd.CommandText = sql cmd.ExecuteNonQuery() ''Inserting TSMS_ORDER_STATUS_HISTORY Table. cmd.CommandText = "insert into " + tabPrefix + "ORDER_STATUS_HISTORY(RFS_NO,ORDER_STATUS_ID,UPDATEDBY)values(@RFS_NO1,@ORDER_STATUS_ID,@UPDATEDBY1)"cmd.Parameters.Add("RFS_NO1", SqlDbType.NVarChar, 50).Value = rfsno cmd.Parameters.Add("ORDER_STATUS_ID", SqlDbType.Int, 50).Value = rfsstatuscmd.Parameters.Add("UPDATEDBY1", SqlDbType.Int, 50).Value = userid cmd.ExecuteNonQuery() trans.Commit()Catch ex As Exception _LastError = ex trans.Rollback() Finally con.Close() End Try End Function
I am getting following error Second time in For loop when control reached to cmd.ExecuteNonQuery(). This Statement. Error is: The variable name '@QUANTITY' has already been declared. Variable names must be unique within a query batch or stored procedure. Please Help me.
We are running into problems using CLR stored procedure in SQL Server 2005. We are using a transaction scope (ambient transaction). If an SQL exception with class 16 is thrown, and this exception is directly caught (and handled) then the transaction is somehow no longer valid. Subsequent use of this transaction gives the message "The current transaction cannot be committed and cannot support operations that write to the log file. Rollback the transaction".
Is there a way to gracefully handle the SqlException and continue the transaction?
I'm taking the liberty to announce the availability of a suite of articles on my web site about error and transaction handling in SQL Server. In total there are three main parts and three appendixes.
The first part is a short jumpstart, while Part Two is a long in-depth discussion of what can happen in SQL Server in case of an error and what commands that are available. Part Three covers implementation and has lot of examples as well as a facility for logging and raising errors.
The appendixes cover special areas: linked servers, the CLR and Service Broker.
Hello, I am reading Microsoft REAL project ETL part. I find that it uses neither transaction nor checkpoints throughtout the packages. I am wondering if something goes wrong with the process and the process aborts in the middle,how are we going to handle this. Any particular reson not using transaction? Is it best practice without using transaction for performance consideration and log volumn? I am new to SSIS. I would like to follow the best practice. Thanks for advice..
We have a required to run multiple procedures in Single Go . And Error Occurred in any Procedure the it will rollback all the changes( Either all Proc run or None)
Problem Statement is its not capturing the Error Message from Either Proc1 or Proc 2., its Capturing the Flat Message (The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction). How do i capture the Error Occurred in Proc 1 or Proc 2 into Log Tables.
I have a need to read a table and extract records that matches a criteria (dough!, not that simple). Then I put the record in a text message and send them out via email. Works OK, but the problem is when I have multiple records for one entry. Since SQL doesn't have arrays "per say", I need to load the records on a "temporary array" then assembly the message at the end to include the records. Any suggestions how to "emulate" an array on a stored procedure (SQL), not sure what direction to follow. thanks
I have been trying to solve the locking problem from past couple of days. Please help mee!!
Scenario: -------------- I have a SSIS package in which 2 data flow tasks. 1st data flow task deletes records from a 5 tables and the 2nd data flow task should insert records into 1 of the five tables after the success of 1st data flow task. This scenario runs in Transacation.
The above scenrio in the 2nd data flow task hangs in runtime. It does not complete. with sp_who2 command i could see that there is an intent share lock(LK_M_IS) on the table and the status is SUSPENDED.
I dont know how to come out of this locking. Please help.
Hi I have created one store procedure which handles global updates I am using cursor to fetch one be one row for updating (It is required for implementing business logic)Now when i execute this store procedure ---it gives me dedlock error , I dont know why i m getting this error(Approx number of rows 1.5lakh)if then i removed unnecessary records from table (Approx -50000) it works fine,Is there any way to handle itI am calling this storeprocedure from my window service.please give me a good solution if possible
I have one ssis package moving the data from staging to destination. In stating table we have the duplicate data. But in destination table 4 columns have primary key. How to handle the duplicate records in oldedb source.
I want to have a query that will return me a single row for each user from a table where the table has many rows for each user. The single returned row for each user must be the most recently dated entry ([I7-Change-Date]) for that user.
An example of the code I have so far is as follows, but it obviously doesn;t work.select DISTINCT([I1-Customer-Ref]) AS Cust,([i7-w-fixed-amnt]) as WaterFixedAmt, ([i7-w-rv-amnt]) as WaterRVAmt, ([i7-s-fixed-amnt]) as SewerageFixedAmt, ([I7-Change-Date]) AS [Date]from r07UnMeasuredBills ORDER BY Cust, [I7-Change-Date] DESC I am using MS SQL Server 7 for this.
Im trying to create a line graph for displaying the number of page views, in this instance for the last 7 days, problem is I would like to dispaly the graph as the last 7 days, so for today, tuesday would be the last day to hold a value on the graph and the six previous would be monday through wednesday descending, currently the values for the graph are thrown in by the day where monday always shows in the same position in the graph which is not that great,, (hope that makes sense)
If I could get the values out of the database in the right order I can use them to display in the graph as like,
Currently this is not as as I like,
SELECT COUNT([Day]) as num,[Day],dDate FROM ListingStats WHERE iListingID=12 AND (dDate <= GetDate() AND dDate >= DateAdd(d,-7,GetDate())) GROUP BY [DAY],dDate ORDER BY [DAY] ASC
where the date is a datetime field, can I trunc this to get just the date so this current format will work? day represents an Enum of the day of the week 1=monday etc
I have a matrix report with STORES in the row group and DATES in the column group. The table sums on SALES. The DATES column is formatted like =format(Fields!DATES.Value, "MMM yyyy"). The table also has 2 parameters @Start and @End. This all works great but I then added a child report so that the user can click on the SALES value for any sale by month and store. The child report uses the @Start and @End parameters from the original report but this is where I run into problems.
Rather than bringing me the sales details for a particular store and month it brings back everything from the time period selected with the original date parameters. So say I originally selected 2015-01-01 to 2015-06-30 with the parameters when I select on FEB 15 in my matrix report I get Febs data along with all the other months ie Jan-Jun 15. The DATES fields in both reports are in the same date format - in fact both reports use exactly the same dataset.
I realize it's something to do with the formatting of the DATE field not being recognized in the linked report.
I have a data column named Date_In with format of 20-May-13. How can I filter the data to select based on year only. I used
Select * From apps.xdmc_852@erpprod Where Year(Date_in) = 2014
This code is not working. I also need a way to automatically update to next week range. For example, last week I used where function like this
Where Date_in = to_date('01/12/2014','MM/DD/YYYY')
Is there a way it will automatically at the next 7 days to the code above when the date is available. This week I have to go back and changed the code in to this:
Where Date_in = to_date('01/19/2014','MM/DD/YYYY')
I'm trying to save several records to an SQL Server 2000 database. The records are in a 1:Many relationship; i.e., there is one record that goes into a parent table, and several that go into a child table. I have to do this with stored procedure(s) that constitute one transaction. Can anyone tell me how this might be done?Thanks!
I am fairly new to SQL Server 2005 and was curious if this was possible.
In my VB applications I always used Begin Transaction, Commit and Rollback to process records. I just found out that I can perform the same functionality in a stored procedure.
So the question is, if I have an order record and four line item records is there anyway to pass all that to the stored procedure as a unit. I can pass the order record as individual parameters but it is the four (or however many) detail records that is the reason for my question. How can I pass the detail records at one time? Can I pass these as an array or a dataset or something else or am I just out of luck? SQL Server 2005 has impressed me a few times already with what you can do and I am really hoping this can be accomplished also.
I use SQLServer2000 when i begin a transaction and update set of records in a table till i don't commit or rollback the transaction nobody can not select previous values of that records and it must wait until i complete the transaction, i have tested it in oracle but it hasn't this limitation don't you think it is Sqlserver weakness?
Currently we has a database of size about 300G. Because our backup system failed some time past we were left with a transaction log file which grew to about 160G. However our backups are working again and everything is working fine. My understanding is that now the transaction log file is practically empty but the capacity remains at 160G.
When you delete records the deleted transactions are going to get logged to the transaction file. My understanding is when a backup is done these transactions get discarded out of the transaction file.
could I make use of this relatively large transaction file and start deleting transactions without out actually adding to the transaction file size.
The plan is to delete records from logging tables that are not referenced to by any other table without this increasing the transaction log file.For example over a period of a few weeks we can delete a chunk of records from a table. Then after it has completed a backup we can delete another chunk of records out of this table until we have got the table down to the records that we now need.Will this work?
In the ECASE table there is trigger to get the max value of case_id column in ecase based on project and increment one to that case_id value and insert into ecase table .
When we insert a new record to the ECASE table this trigger calls and insert the case_id column value.
When i run with multiple threads , the transaction is rolled back because of trigger . The reason is , on the project table the lock is happening while getting the max value of case_id column based on project.
I'm getting this when executing the code below. Going from W2K/SQL2k SP4 to XP/SQL2k SP4 over a dial-up link.
If I take away the begin tran and commit it works, but of course, if one statement fails I want a rollback. I'm executing this from a Delphi app, but I get the same from Qry Analyser.
I've tried both with and without the Set XACT . . ., and also tried with Set Implicit_Transactions off.
set XACT_ABORT ON Begin distributed Tran update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.TRANSACTIONMAIN set REPFLAG = 0 where REPFLAG = 1 update TSADMIN.TRANSACTIONMAIN set REPFLAG = 0 where REPFLAG = 1 and DONE = 1 update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.WBENTRY set REPFLAG = 0 where REPFLAG = 1 update TSADMIN.WBENTRY set REPFLAG = 0 where REPFLAG = 1 update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.FIXED set REPFLAG = 0 where REPFLAG = 1 update TSADMIN.FIXED set REPFLAG = 0 where REPFLAG = 1 update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.ALTCHARGE set REPFLAG = 0 where REPFLAG = 1 update TSADMIN.ALTCHARGE set REPFLAG = 0 where REPFLAG = 1 update OPENDATASOURCE('SQLOLEDB','Data Source=10.10.10.171;User ID=*****;Password=****').TRANSFERSTN.TSADMIN.TSAUDIT set REPFLAG = 0 where REPFLAG = 1 update TSADMIN.TSAUDIT set REPFLAG = 0 where REPFLAG = 1 COMMIT TRAN
It's got me stumped, so any ideas gratefully received.Thx
I have a design a SSIS Package for ETL Process. In my package i have to read the data from the tables and then insert into the another table of same structure.
for reading the data i have write the Dynamic TSQL based on some condition and based on that it is using 25 different function to populate the data into different 25 column. Tsql returning correct data and is working fine in Enterprise manager. But in my SSIS package it show me time out ERROR.
I have increase and decrease the time to catch the error but it is still there i have tried to set 0 for commandout Properties.
if i'm using the 0 for commandtime out then i'm getting the Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.
and
Failed to open a fastload rowset for "[dbo].[P@@#$%$%%%]". Check that the object exists in the database.
I am getting this error :Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.have anybody idea?!
i have a sequence container in my my sequence container i have a script task for drop the existing tables. This seq. container connected to another seq. container. all these are in for each loop container when i run the package it's work fine for 1st looop but it gives me error for second execution.
Message is like this:
Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.
i am getting this error "Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.".
my transations have been done using LINKED SERVER. when i manually call the store procedure from Server 1 it works but when i call it through Service broker it dosen't work and gives me this error.
I have a requirement to delete 1 Million records from a table having 10 Million data and it's being queried on 24/7 basis (don't have a downtime). how can I achieve that?
writing the query for the following, I need to collapse the continuity. If the termdate for an ID is one day less than the effdate of the next id (for the same ID) i need to collapse the records. See below example .....how should i write the query which will give me the desired output. i.e., get min(effdate) and max(termdate) if termdate is one day less than the effdate of next record.
I have Full database backup upto previous day and transaction logfile of Today transaction. my database has crashed. I have restored previous day's Full backup. I have faced difficulty to restore today's transaction from today's transaction log. What are the steps to restore full database back and one day's transaction log file. Note: there is no differential database backup and transaction backup.
I'm receiving the below error when trying to implement Execute SQL Task.
"The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION." This error also happens on COMMIT as well and there is a preceding Execute SQL Task with BEGIN TRANSACTION tranname WITH MARK 'tran'
I know I can change the transaction option property from "supported" to "required" however I want to mark the transaction. I was copying the way Import/Export Wizard does it however I'm unable to figure out why it works and why mine doesn't work.