how to restore back the id generated if the package fails
Using cdn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(Me.Connections.Connection.ConnectionString) Dim cmd As System.Data.OleDb.OleDbCommand = cdn.CreateCommand() Dim result As Integer cdn.Open() cmd = New OleDb.OleDbCommand("select IDENT_CURRENT('sec_id_customer')", cdn) result = cmd.ExecuteScalar() result = result + 1 Row.scriptsecondaryid = result cmd = New OleDb.OleDbCommand("DBCC CHECKIDENT ('sec_id_customer',RESEED," + CStr(result) + ")", cdn) cmd.ExecuteNonQuery() cdn.Close() End Using fuzailrashid HI rashid why are you forcing identity insert in oledb Destination ? and in case of failure would you want to delete the records loaded ? any ways i believe you have given only piece of your code .. what u can do is have an execute SQl task [before dataflow]: that will set a variable [say lastIdentity] in execute sql task set this variable value to current identity value similar to what ur script component is fetching 1st time in result : cmd = New OleDb.OleDbCommand("select IDENT_CURRENT('sec_id_customer')", cdn) now in case of failure : add an event handler : have another execute sql task / script task to reseed your table with lastIdentity variaBLE that you had stored in the start of the package ... i hope rolling back already loaded records you are taking care off ...Hope that helps ... Kunal
December 21st, 2010 9:30pm

I have a package in which a identity is generated when a new a record is created. In my package I am getting the previous value of that identity before inserting the data and when a new record comes so for that the value will previous identity value+1 . when I execute the package and for some reason the package fails,the identity gets incremented to the no of input rows coming from the source. for example,if 1000 rows coming from source and the previous vlaue of that identity is 1000 ,before inserting the record into oledb destination it gets incremented 2000.then the current identity value becomes 2000. if I rerun the packge,the identity becomes 2000 but it should be 1000. I have a script compnent for this process before inserting into target table and i want to roll back the secondaryid to the earlier value if the package fails. this is the code I have used in the script component Using cdn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(Me.Connections.Connection.ConnectionString) Dim cmd As System.Data.OleDb.OleDbCommand = cdn.CreateCommand() Dim result As Integer cdn.Open() cmd = New OleDb.OleDbCommand("select IDENT_CURRENT('sec_id_customer')", cdn) result = cmd.ExecuteScalar() result = result + 1 Row.scriptsecondaryid = result cmd = New OleDb.OleDbCommand("DBCC CHECKIDENT ('sec_id_customer',RESEED," + CStr(result) + ")", cdn) cmd.ExecuteNonQuery() cdn.Close() End Usingfuzailrashid
Free Windows Admin Tool Kit Click here and download it now
December 21st, 2010 10:27pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics