Hello
I am trying to run a program to check for transaction scope
I have written the following code.
But it seems I need to add a namespace or reference
What namespace am I supposed to add
thanks
using (TransactionScope scope = new TransactionScope(TransactionScope.Required, options))
{
SqlConnection MyCon = new SqlConnection("server=hemalatha\sqlexpress;integrated security=sspi;database=demo");
MyCon.Open();
SqlCommand Mycmd=new SqlCommand("insert into t1 values 574,'scope','10/10/2007',3,3,3");
Mycmd.ExecuteNonQuery();
SqlConnection MyCon1 = new SqlConnection("server=hemalatha\sqlexpress;integrated security=sspi;database=persons");
MyCon1.Open();
SqlCommand Mycmd1 = new SqlCommand("insert into persons values 'scope',123,123,12,'scope'");
Mycmd1.ExecuteNonQuery();
I am having some problem with SSIS transaction. Eventhought I tried to imitate the concept that Jamie presented at http://www.sqlservercentral.com/columnists/jthomson/transactionsinsqlserver2005integrationservices.asp
. My workflow is as followed
********************************* For Each ADO.Record in Oracle (transaction=not supported)
If (Certain_Field_Value = 'A')
Lookup Data in SQL DB with values from Oracle (transaction=not supported)
DO Sequence A (Start a Transaction , transaction=required)
INSERT/UPDATE some records in SQLDB(transaction=supported) Finish Sequence A ( transaction should stop here) UPDATE Oracle DB ( Execute SQLTask, transaction=not supported) If (Certain_Field_Value = 'B')
Lookup Data in SQL DB with values from Oracle (transaction=not supported)
DO Sequence B (Start a Transaction , transaction = required)
INSERT/UPDATE some records in SQLDB (transaction=supported) Finish Sequence A ( transaction should stop here) UPDATE Oracle DB ( Execute SQLTask, transaction=not supported) If (Certain_Field_Value = 'C')
------------ ------------ End ForEach Loop ************************************* My requirements are that I want separate transaction for each Sequence A, B, C, etc... If Sequence A transaction fails, the other should still be continuing with another transaction. But I am getting an error regarding the OLEDB Error in next Task (e.g in Certain_Field_Value = 'B') "Lookup Data in SQL DB with values from Oracle ", the error message is ".......Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction. ". What is it that I am doing wrong? Regards KyawAM
I have 2 packages and they get executed in SQL Job.
Each of these package will have seperate transactions with the Database and I am not sure of how to maintain the transactions between these 2 packages.
Can someone explain me the necessary setting to achieve this. If I set the TransactionOption property to Required (or) Supported in both these packages, will the Transaction Scope of the first package extend to the second one.
For me, If the second package ends up in error, the first package should also have to be rollbacked.
Hi, i'm trying to run wrap a transaction around a block of code to make sure every statement is carried out. Here's what i have: using (TransactionScope ts = new TransactionScope()) { ... ts.Complete();}The code executed in the ... part is a set of sql commands within my dal. If this above expression takes less than 30 seconds everything is carried out correctly, however if it takes longer than 30 seconds i receive an sql timeout error. I tried modify the above code to: using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromMinutes(5))) { ... ts.Complete();} But it did not seem to make a difference. I suppose the easiest option would be to increase the timeout for every sql command in my dal but i feel that the 30 second timeout is sufficient for a single command. Appreciate if someone could tell me how this should be done correctly. Thanks
Hello, I've a problem with a software developed in C# with the framework 2.0. This is the error I receive : The operation could not be performed because OLE DB provider "SQLNCLI" for linked server "XXX_LINKED_SERVER" was unable to begin a distributed transaction. OLE DB provider "SQLNCLI" for linked server "XXX_LINKED_SERVER" returned message "No transaction is active.". If I try directly to restart the process, it works fine. Is there someone who can help me ? This is the process 1. In C# --> Call of a Query : select from the linked server (db in sql 2005) and insert into a table SQL 2005 2. In the C# --> using (TransactionScope scope = new TransactionScope()) and insert in a table in SQL 2005 which is link server Thank in advance.
we have an update sp that must call an insert sp after the update. The update and insert must act like a transaction, ie all or none.
We believe that wrapping most of the update (including call to insert sp) sp in a begin tran block would guarantee the all or none behavior.
However, we're not sure what would happen if one of our developers calls the update sp from within a transaction scope that expects yet something additional to be included in the transaction. Would the begin tran block (assuming no errors in that block) in the sp commit both the update and insert regardless of what happens in the rest of the .net tran scope?
BEGIN TRANSACTION Copy records from live to archive END TRANSACTION with commit or rollback execute sproc to write audit log with success or fail IF transaction was committed BEGIN TRANSACTION Delete records from live the archive END TRANSACTION with commit or rollback execute sproc to write audit log with success or fail End IF
END TRANSACTION OUTERTXN with commit if both inner transactions were successful or rollback if either failed
If either inner transaction rolled back execute sproc to write audit log saying whole process is rolling back End IfMy problem is that if the outer transaction rolls back then I am losing the two audit records because they are part of the transaction scope. I want these executes to commit even if the master transaction fails.
I followed Remus' post about not doing 'fire and forget'.
I have two queues, ProcessingSendQueue and ProcessingReceiveQueue.
Once i receive from ProcessingReceiveQueue, activation SP gets called on ProcessingSendQueue and ends conversation.
However,if I then get an exception, the action of the activation SP ( ie the ending of the conversation ) does not get rolled back... is this possible? I would have thought that the action of the activation SP would get rolled back too.
My ProcessingSendQueue activation SP is as follows:
ALTER PROCEDURE [dbo].[ProcessingSendQueue_AP] AS BEGIN DECLARE @dh UNIQUEIDENTIFIER; DECLARE @message_type SYSNAME; DECLARE @message_body NVARCHAR(4000);
RECEIVE @dh = [conversation_handle], @message_type = [message_type_name], @message_body = CAST([message_body] AS NVARCHAR(4000)) FROM [ProcessingSendQueue];
IF @dh IS NOT NULL BEGIN IF @message_type = N'http://schemas.microsoft.com/SQL/ServiceBroker/Error' BEGIN RAISERROR (N'Received error %s from service [ProcessingReceiveQueue]', 10, 1, @message_body) WITH LOG; END END CONVERSATION @dh; END END
I have taken three dtsx files and re written them into one each in its own container. I use the XML Task task alot which the File connection is set by a variable and the variable value is evaluated by expression (the expression makes up the path/filename from other variable values). All the variables that make up the connection are at the container scope. The package will not run now because it is saying that the source (created by variables) for the file connection do not exist.
It seems the answer is that file connections exist at the package level therefore the variable has to be at the package level. This seems to be alot of variables i now have to move to package level to generate the XML source connection. Which in essence makes it confusing as to which variables operate in which container.
My question is can we easily move variable scope (Not ideal as we have alot of variables at package level) Or Can we do the same for connection managers as we do for variables and have them only used in a scope? (this will be ideal as some connections only need to be at a container scope)
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 been using tis page as a reference http://forums.asp.net/thread/1511323.aspxbut i cant seem to get this to work. The above page suggests using Dim newId As Object = e.Command.Parameters("@RETURN_VALUE").Value to get the value but when i do that i get an error that Command is not a member of system.web.ui.webcontrols.formViewInsertedEventArgs Can anyone help?ThanksMatt
Hi folks I'm using a function to create a record on a database, and then I want to return the ID of that record to passinto another function. I believe its scope identity that does this, but I'm not sure how to do it. public static void putrecordin(string record) { SqlCommand cmd = new SqlCommand("insert Table (record) values (@record; scope identity)" conn.Open(); cmd.Parameters.Add(new SqlParameter("@record", record)); cmd.ExecuteNonQuery(); conn.Close(); another(new-record-ID, anothervalue); } public static void another(string new-record-ID) {do stuff } so you'll see I have a function called putrecordin, and at the end of the sql statment I want to return the id of the new record and pass it into another function called another. Anyone know how to do this? Thanks!
In the following Query, is Table1.Column3 updated in the subquery for each row in Table1, or does it take the first value, or is it NULL, or is it ____?
Select Column1, Column2 from Table1 where Column1 IN (Select Col1 from Table2 where Col2 > Table1.Column3 Group by Col1 Having count(Col1) > 1) and Table1.Column3 < Column4
To Parse it out. This then has to be inserted into another table with an identity column (damn Identity column), and I need to grab the generated id for each row, because then there are other children tables that need to be populated.
Question: Is there any set way to grab multiple generated id's? Or do I need to loop or use a cursor?
Is an index in a database the equivalent for a <TH scope="col"> in a columnof atable in the html code?--Luigi ( un italiano che vive in Svezia)https://www.scaiecat-spa-gigi.com/s...kor-italien.php
I've been trying to figure out the usage of "Nothing" as the scope parameter, and the more I try, the more I can confused.
It says on the RDL spec:
"For expressions inside data regions:
.......
Specifying the keyword Nothing as the scope is equivalent to specifying the outermost data region containing the report item in which the aggregate is used."
It seems that what's it saying is that if I have an expression in a table as = last(somefield, "the name of the table") is the same as = last(somefield,Nothing) But, apparently it;s not. (I tried last, first,sum, count,CountRows, min, max...........) it doesn't matter where I put "=last(somefield,Nothing)" in the table (i tried table header,footer, detail, and table group header, footer), none of them worked. and I tried it everywhere in matrix, in charts. It's just not working. It always complains about the invalid scope not being the containing data region, containing grouping or dataset name.
However, the only way I get the "Nothing" as the scope to work is in a RunningValue function, not in any other aggregate funcitons.
Anyone help me with this, please... I need a complete definition on the usage of Nothing as scope.
Variable scope of package variables should be in a dropdown. I want to copy (20+) variables from one sequence container to another. Do I have to retype all the names, types and initial values because I made the mistake not to place them one level higher?
I am really starting to like CTEs. My only qualm is that you can only use them within the first statement after you declare them. I wish they would remain active for the duration of the sql batch just like everything else (variables,local temp tables, ect). Is there any trick so that you can use them multiple times? Maybe define them as a string and do dynamic sql or something like that? Hopefully (i have not researched the new version of sql server) in SQL Server 2008 the scope has increase. Anyways any help would be appreciated.
Hi, I've been trying to insert data in a Sql server (.mdf) db and use SCOPE IDENTITY to be able to insert an id in both the parent and the child tables. However, I don't know how to write one of the lines correctly: Dim MyConn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString) Dim MySQL As String = "INSERT INTO Document (fid, serie, vnr, datum, vtext, sign) " & _ "Values (@fid, @serie, @vnr, @datum, @vtext, @sign) Select @verid=SCOPE_IDENTITY()" Dim Cmd As New SqlCommand(MySQL, MyConn) With Cmd.Parameters .Add(New SqlParameter("@fid", fid)) .Add(New SqlParameter("@serie", SerieDropDownList.SelectedValue)) .Add(New SqlParameter("@vnr", vnr)) .Add(New SqlParameter("@datum", datumet)) .Add(New SqlParameter("@vtext", VtextTextBox.Text)) .Add(New SqlParameter("@sign", sign)) .Add(New SqlParameter("@verid", SqlDbType.Int)) 'HERE IS THE LINE THAT SHOULD BE CHANGED (OR SO I THINK) End With MyConn.Open() Cmd.ExecuteNonQuery() Dim p As SqlParameter = Cmd.Parameters.Add("@verid", SqlDbType.Int) p.Direction = ParameterDirection.Output Dim verid = Cmd.Parameters("@verid").Value.ToString For Each row As GridViewRow In StampelGridView.Rows Dim kpnr As String = row.Cells(0).Text Dim kst As String = row.Cells(1).Text If kst = " " Then kst = "" Dim projekt As String = row.Cells(2).Text If projekt = " " Then projekt = "" Dim debettext As String = "0.00" Dim kredittext As String = "0.00" If row.Cells(3).Text.Length > 3 Then debettext = Replace(row.Cells(3).Text, ",", ".") If row.Cells(4).Text.Length > 3 Then kredittext = Replace(row.Cells(4).Text, ",", ".") Dim ptext As String = row.Cells(5).Text If ptext = " " Then ptext = "" Dim MySQLpost As String = "INSERT INTO Vpost (verid, kpnr, kst, projekt, debet, kredit, ptext) " & _ "Values (@verid, @kpnr, @kst, @projekt, @debet, @kredit, @ptext)" Dim Cmdpost As New SqlCommand(MySQLpost, MyConn) With Cmdpost.Parameters .Add(New SqlParameter("@verid", p)) 'THIS SHOULD CHECK OUT AS WELL... .Add(New SqlParameter("@kpnr", kpnr)) .Add(New SqlParameter("@kst", kst)) .Add(New SqlParameter("@projekt", projekt)) .Add(New SqlParameter("@debet", debettext)) .Add(New SqlParameter("@kredit", kredittext)) .Add(New SqlParameter("@ptext", ptext)) End With Cmdpost.ExecuteNonQuery() Next MyConn.Close() In other words, the verid is the id of the new post in the first table. This id should be inserted in the new table as well. Thank you very much in advance fro helping me out! I've worked a LONG time with this. Pettrer
Is it possible to write the InsertCommand for a SqlDataSource to return the value of the AUTONumber of a field generated when a new record is added to a database table and display that value on label1.Text after the postback of ItemInsersted event? For example, <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NearMissConnectionString >" InsertCommand="INSERT INTO [NearMiss] ([Branch], [Division] VALUES (@Branch, @Division); SELECT SCOPE_IDENTITY()" SelectCommand="SELECT [NearMissID], [Branch], [Division], FROM [NearMiss]" <InsertParameters> <asp parameter Name="Branch" Type="Int32" /> <asp parameter Name="Division" Type="String" /> </InsertParameters> </asp:SqlDataSource>
NearMissID would be the value of the autonumber generated by the SQL Server
I am trying to retrieve the value of the autonumber generated when a new record is inserted into a SQL 2000 Database using a SqlDataSource attached to a FormView. Is this possible? Can some give me a short example of how to retrieve that value and display it in a textbox? Thanks for any help with this. It seems like it would be a common issue for .net developers.
Hi, I have been trying to get the scope Identity after inserting a record using an ObjectDataSource. I can't find what event, or how to get the value that the scope identity returns. Here is my Sproc.
ALTER PROCEDURE dbo.[YourCompany_LanCustomer_Insert] ( @DNNUserID int, @FirstName nvarchar(50), @LastName nvarchar(50), @Address nvarchar(50), @Address2 nvarchar(50), @City nvarchar(50), @State nvarchar(50), @Zip nvarchar(50), @EmailAddress nvarchar(50), @PhoneNumber nvarchar(50), @CustomerID int OUTPUT ) AS INSERT INTO YourCompany_LanCustomer (DNNUserID, FirstName, LastName, Address, Address2, City, State, Zip, EmailAddress, PhoneNumber, DateEntered) VALUES (@DNNUserID, @FirstName, @LastName, @Address, @Address2, @City, @State, @Zip, @EmailAddress, @PhoneNumber, getdate()) SET @CustomerID = Scope_Identity() RETURN
This is kind of what I'm trying to do in my MS SQL 2000 query. ShouldI be able to reference s1.col1 inside the 2nd derived table?I'm getting 'Invalid column name col1' and it's coming from the 2ndderived table (I've commented out other refs to just it to check).Maybe I need to use a temp table instead.SELECT s1.col1,(SELECT * FROM(SELECT COUNT(zzz) AS SomeTotalFROM tab1WHERE s1.col1 = zzz)) AS RowCount) /* error here */FROM(SELECT col1 FROM table) AS s1Thank you!
We're working on a new release of a software.In the existing version, each client connects and executes a long batch ofanalysis on some tables.In the new release, we need to allow each client to execute analysis on asubset of data, according to certain login information.Our idea is:1) Connection to db2) Creation of one View according to restrictions3) Execution of analysis using just created view and some tables.The problem is that executingcreate view myvista asselect * from tb_data where testo='A1'from two different clients, creates just one view.Question: Does it exist a way of creating a VIEW with a connection scope,something like 'select into ##temptable'?We tried Create View #MyVista or ##Myvista, but this name is not accepted.Alternative way, is creating a ##TempTable, at the beginning of the batch,and using it as data source instead of full table, but, due to really hugeamount of data, this could really disturb server performances.Thanks for any helpAlberto