Transaction+TableAdapters

May 14, 2007

Hi,

I have problem vith implementing Transaction with TableAdapters. My code is:

try

{

using (bookTableAdapter adapter = new bookTableAdapter())

{

transaction = TableAdapterHelper.BeginTransaction(adapter);

ID=(Guid) adapter.bookInsertNew(bookOrgId, bookISBN, bookName, Convert.ToInt32(bookYear), publisherId, languageId, orgLanguageId, bookTranslation, Convert.ToInt32(bookColors), Convert.ToInt32(bookPages), bookFormat, Convert.ToDouble(bookWidth), Convert.ToDouble(bookHeight), Convert.ToDouble(bookWeight), Convert.ToDouble(bookThickness), Convert.ToInt32(bookPrize), bookResumeText, bookResumeHtml, bookPicture_s, bookPicture_m, bookPicture_l, Convert.ToInt32(bookStatusId));

 

}

using (bookAuthorTableAdapter adapter1 = new bookAuthorTableAdapter())

{

TableAdapterHelper.SetTransaction(Adapter1, transaction);

 

for (int i = 0; i <= leng1; i++)

{

adapter1.Insert(author[i],ID,1);

 

}

}

transaction.Commit();

}

catch

{

transaction.Rollback();

throw;

}finally

{

transaction.Dispose();

}

First Insert is ok, but trow exception on second try to insert in database.

Exceprion is :
Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
The statement has been terminated.

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.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
The statement has been terminated.

Source Error:





Line 1839: }
Line 1840: try {
Line 1841: int returnValue = this.Adapter.InsertCommand.ExecuteNonQuery();
Line 1842: return returnValue;
Line 1843: }

 I also set Connect Timeout=200 in Web.config but nothing change :(

Please help :( :( :(

 

 

View 1 Replies


ADVERTISEMENT

TableAdapters

May 23, 2008

I moved from using data adapters to tableadapters. This is my sql query that is included in my data adapter

sql = "SELECT f.Date, CPT, CPTModifier, CPTModifier2, Description, Fee, Tax, Balance, [SPatient Number]
FROM Financial f
INNER JOIN Demographics d ON d.[Patient Number]=f.[SPatient Number] WHERE (f.[SPatient Number]= (" & intPID & "))"

conn.ConnectionString = My.Settings.EbtblsConnectionString
da = New SqlDataAdapter(sql, conn)

intPID is an input box that a user types a number in and compares it to SPatient Number on the Financial table. The query has been working fine.

However, when I go into designer view and hit the table adapter's "add query" property, in vs2008. I put that query in, and it gives me an error saying that intPID is not a valid column. I am aware it's not a valid column..because it isn't a column, it's a variable in the windows form. How do I put a variable in the sql string for table adapters?

View 2 Replies View Related

Should I Use TableAdapters Or DataAdapters For My DAL?

Feb 26, 2008

So I just created a very nice dataset class with 30+ tables and relationships for a very large project. Each table has 3-8 associated queries besides the usual Fill/Get and then there will be many more in the BLL that utilize this DAL.  I then created a BaseDAL class and other DAL classes that inherit from the BaseDAL(has basic sql query access if needed).  What I want to know is if the way I am doing this is correct and if this is a good idea for a database of this size.  I've never used TableAdapters before and I don't know if I should be using them at all?  I don't know how they handle connections and if one user will have more than one connection open because of using them or will they all share an open connection? 
 Can someone please direct me.  Thank you! Also, if you notice in the top of the UserDAL code I have listed below, I declare and initialize the usersTableAdapter and usersDeptTableAdapter.  Should the call to create the object be moved into each function?Public Class Users : Inherits BaseDAL
Private usersDS As OEE_USERSTableAdapter = New OEE_USERSTableAdapter()Private usersDeptDS As OEE_USER_DEPTSTableAdapter = New OEE_USER_DEPTSTableAdapter()Private retcode As Integer = 0
 
#Region "USER"
' Returns employee ID if user is in system, otherwise returns 0
Public Function ValidateUser(ByVal username As String) As String
'Dim usersDS As OEE_USERSTableAdapter = New OEE_USERSTableAdapter()Dim dtUser As New OEE_USERSDataTable
dtUser = usersDS.GetUser(username)
If dtUser.Rows.Count = 1 ThenReturn dtUser.Rows(0)("EMPLID").ToString
Else
Return "0"
End IfEnd Function
 
'Add User
Public Function InsertUser(ByVal emplid As String, ByVal username As String) As String
Dim insertedEmplid As String = ""
emplid = usersDS.AddUser(emplid, username)Return insertedEmplid
End Function
Public Function FlagAsInactive(ByVal emplid As String) As Boolean
retcode = usersDS.FlagAsInactive(emplid)Return retcode <> 0
End Function
'Sets inactive flag to null for user (Reactivates them)
Public Function ActivateUser(ByVal emplid As String) As Boolean
retcode = usersDS.ActivateUser(emplid)
Return True
End Function
'Returns list of all usersPublic Function GetUsers() As DataTable
Return usersDS.GetUsers
End Function
#End Region

View 2 Replies View Related

SQL Server 2005 And TableAdapters

Dec 11, 2006

Hello.  I have been using Table Adapters in VS2005 for the last several
projects and love them.  However, when I am connecting to a 2005 SQL
Server database, I have problems connecting.  That is, I cannot create
new stored procedures with the TableAdapter Config Wizard.  For
instance, I try to create a new query.  I use the wizard to create my
SQL statement and continue through until then end of the wizard, when
it asks me to "finish".  At this point, I get an error --  This only happens when trying to connect to a 2005 table.  Any ideas?  

View 1 Replies View Related

TableAdapters With Multiple Queries

Jul 18, 2007

Hello everyone...
I have created a report that pulls data from 5 different tables. I have created a tableadapter for this. I have a sql stored procedure with left joins that I am trying to use but keep getting key violations and not null value violations when I try to use it. I have tried setting the NULLValue to NOT throw exception but that has not helped. I have also tried to writing a query for each table. I can add each query to my tableadapter but I can use them all at the same time for some reason. Can this be done? When I go to my report and try to add fields to it from the tableadapter, I only see the results of one query. I am only trying to SELECT. I am not doing any updates or deletes to the tables on the SQL Server.
 Any advice would be greatly appreciated.

View 4 Replies View Related

TableAdapters And Custom SQL Statements

Nov 15, 2007

 
I've been working with TableAdapters, DAL, and BLL for a few months
now.  At this point, most of my new queries are too customized with
multiple tables to fit into any of my existing TableAdapter schema's. For
instance, if I want to execute an aggregate function with group by's
and counts that includes three separate tables, how would I go about
doing this with a strongly typed DAL using TableAdapters.  My
workaround to this point is to just create a whole new TableAdapter for
that one query.Is there anyway to extend the DAL in a strongly
typed dataset to create these "read-only" aggregate queries, or should
I continue to create new TableAdapters for each one of these queries?
 What's the proper way to handle such customized SQL statements that
don't fit any of my existing TableAdapters?

View 3 Replies View Related

Problem With Return Value Of Stored Procedure When Using Tableadapters

Dec 8, 2007

hello
Could you please help me with this problem?
I have a stored procedure like this:
ALTER PROCEDURE dbo.UniqueChannelName
(
@UserName nvarchar(50),
@ChannelName nvarchar(50)
)
AS
return 5;
 
Then inside of my dataset, I added a new query(dataset1.QueriesTableAdapter) to handle above mentioned stored procedure. Properties window is showing that return type of this adapter is of type int32 as we expected to be.
now I want to use it inside of my code:
DataSet1TableAdapters.QueriesTableAdapter b = new DataSet1TableAdapters.QueriesTableAdapter();
int i;
i=Convert.ToInt32( b.UniqueChannelName("Ahmad", "test"));
as you may guess, the return type of  b.UniqueChannelName("Ahmad", "test") is object and needs to be type-casted before assigning it's value to i; but even after explicit type casting, the value of i is always set to 0, not 5.
could you please show me the way?
many thanks in advance

View 19 Replies View Related

XMLDocument I/O With DataTables And TableAdapters (final Version?)

May 25, 2006

The test sub below operates on a SQL Server Table  with an xml-type field ("xml").  The purpose of the sub is to learn about storing and retrieving a whole xml document as a single field in a SQL Server table row.When the code saves to the xml field, it somehow automagically strips the xml.document.declaration (<?xml...>).  So when it reads the xml field back and tries to create an xmldocument from it, it halts at the xmldocument.load.I order to  get the save/retrieve from the xmlfield to work, I add the <?xml declaration to the string when I read it back in from the xml field (this is in the code below).At that point the quickwatch on the string I'm attempting to load into the xmldocument is this:-----------------------------------------------------<?xml version="1.0" encoding="utf-16" ?><Control type="TypeA"><Value1><SubVal1A>Units</SubVal1A><SubVal1Btype="TypeA">Type</SubVal1B></Value1><Value2><SubVal2A>Over</SubVal2A><SubVal2B>Load</SubVal2B></Value2></Control>-----------------------------------------------------The original xml document string is this:-----------------------------------------------------<?xml version="1.0" encoding="utf-16" ?><Control type="TypeA">     <Value1>          <SubVal1A>Units</SubVal1A>          <SubVal1B type="TypeA">Type</SubVal1B>          </Value1>     <Value2>          <SubVal2A>Over</SubVal2A>          <SubVal2B>Load</SubVal2B>     </Value2></Control>-----------------------------------------------------which seems to have all the same characters as the quickwatch result above, but clearly is formatted differently because of the indenting.THE FIRST QUESTION:  Is there a simpler way to do this whole thing using more appropriate methods that don't require adding the xml.document.declaration back in after reading the .xml field, or don't require using the memorystream to convert the .xml field in order to load it back to the XML document.THE SECOND QUESTION:  Why does the original document open in the browser with "utf-16", but when I write the second document back to disk with "utf-16" it won't open...I have to change it to "utf-8" to open the second document in the browser.Here's the test sub'============================================               Public Sub XMLDSTest()          '===========================================          Dim ColumnType As String = "XML"                    '===========================================          '----------Set up dataset, datatable, xmldocument          Dim wrkDS As New DSet1()          Dim wrkTable As New DSet1.Table1DataTable          Dim wrkAdapter As New DSet1TableAdapters.Table1TableAdapter          Dim wrkXDoc As New XmlDocument          wrkXDoc.Load(SitePath & "App_XML" & "XMLFile.xml")          Dim str1 = wrkXDoc.OuterXml          Dim wrkRow As DSet1.Table1Row          wrkRow = wrkTable.NewRow          '=======WRITE to SQL Server==============          '------ build new row          With wrkRow               Dim wrkG As Guid = System.Guid.NewGuid               TestKey = wrkG.ToString               .RecordKey = TestKey               .xml = wrkXDoc.OuterXml     '<<< maps to SQL Server xml-type field          End With          '----- add row to table and update to disk          wrkTable.Rows.Add(wrkRow)          wrkAdapter.Update(wrkTable)          wrkTable.AcceptChanges()          '----- clear table          wrkTable.Clear()          '=======READ From SQL Server ==============          '----refill table, read row,           wrkAdapter.FillBy(wrkTable, TestKey)          Dim wrkRow2 As DSet1.Table1Row = _             wrkTable.Select("RecordKey = '" & TestKey & "'")(0)          '=====  WRITE TO New .xml FILE ===========================          Dim wrkS1 As New StringBuilder          Select Case ColumnType               Case "XML"                    '---if xml build xml declaration:                      '---add this to xml from sql table   =>  <?xml version="1.0" encoding="utf-16" ?>                    wrkS1.Append("<?xml version=" & Chr(34) & "1.0" & Chr(34))                    wrkS1.Append(" encoding=" & Chr(34) & "utf-16" & Chr(34) & " ?>")                    wrkS1.Append(wrkRow2.xml)          End Select          Dim wrkBytes As Byte() = (New UnicodeEncoding).GetBytes(wrkS1.ToString)          Dim wrkXDoc2 As New XmlDocument          Dim wrkStream As New MemoryStream(wrkBytes)          wrkXDoc2.Load(wrkStream)          '===========================================          '---- this just shows that the file actually was touched           Dim wrkN2 As XmlNode = wrkXDoc2.CreateNode(XmlNodeType.Text, "ss", "TestNode2")          wrkN2 = wrkXDoc2.SelectSingleNode("//Value1/SubVal1B")          wrkN2.Attributes("type").Value = "This was from the xml field"          '----------------          '------  update the encoding....otherwise the file won't open in the browser with utf-16          Dim wrkN1 As XmlNode = wrkXDoc2.CreateNode(XmlNodeType.Element, "ss", "TestNode")          wrkN1 = wrkXDoc2.FirstChild          wrkN1.InnerText = Replace(wrkN1.InnerText, "utf-16", "utf-8")          '------------Now write the file back as an .xml file          Dim wrkFilePath As String = SitePath & "App_XML" & "XMLFile2.xml"          Dim wrkXW As XmlWriter = XmlWriter.Create(wrkFilePath)          wrkXDoc2.WriteContentTo(wrkXW)          wrkXW.Close()     End Sub===============================

View 8 Replies View Related

Error 8525: Distributed Transaction Completed. Either Enlist This Session In A New Transaction Or The NULL Transaction.

May 31, 2008

Hi All

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

View 1 Replies View Related

SSIS, Distributed Transaction Completed. Either Enlist This Session In A New Transaction Or The NULL Transaction.

Feb 22, 2007

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.

Please help me it's very urgent.

View 3 Replies View Related

Distributed Transaction Completed. Either Enlist This Session In A New Transaction Or The NULL Transaction.

Feb 6, 2007

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?!

View 1 Replies View Related

Distributed Transaction Completed. Either Enlist This Session In A New Transaction Or The NULL Transaction.

Dec 22, 2006

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.

View 8 Replies View Related

Distributed Transaction Completed. Either Enlist This Session In A New Transaction Or The NULL Transaction. (HELP)

Jan 8, 2008

Hi,

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.



Thanks in advance.


View 2 Replies View Related

SQL Server Admin 2014 :: Restore Lost Transaction From Transaction Log File

Jun 10, 2015

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.

View 8 Replies View Related

I Need Away To Show The Pending Transaction From Transaction Replication In A User Friendly Format.

Jul 11, 2007



I want to list out the pending transaction for transaction replication by publication.



Help needed.

View 1 Replies View Related

TRANSACTIONS In SSIS (error: The ROLLBACK TRANSACTION Request Has No Corresponding BEGIN TRANSACTION.

Nov 14, 2006

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.

Anyone know of the reason?

View 1 Replies View Related

Analysis :: Find Amount Distribution Across Different Transaction Types Under Spend Transaction

Jul 27, 2015

I created a Calculated measure in cube something like this : ([TransType].[TransTypeHierarchy].[TransTypeCategoryParent].&[SPEND],[Measures].[Transaction Amount]). To get only spend transactions. Now, I want to slice this measure with same hierarchy to find the amount distribution across different transaction types under spend transaction. But this query behaving like the measure doesn't have relation with measure.

you can think this as below query:
WITH
MEMBER SPEND AS ([TransType].[TransTypeHierarchy].[TransTypeCategoryParent].&[SPEND],[Measures].[Transaction Amount])
SELECT NON EMPTY {SPEND} ON 0
,NON EMPTY ([TransType].[TransTypeHierarchy].[TransTypeCategoryParent]) ON 1
FROM [CUBE]

View 6 Replies View Related

How Do I Make Use Of Begin Transaction And Commit Transaction In SSIS.

Jun 1, 2007

Hi



How do I make use of begin transaction and commit transaction in SSIS.

As am not able to commit changes due to certain update commands I want to explicitly write begin and commit statements. but when i make use of begin and commit in OLEDB commnad stage it throws an error as follows:

Hresult:0x80004005

descriptionyntax error or access violation.



its definately not an syntax error as i executed it in sql server. also when i use it in execute sql task out side the dataflow container it doesnt throw any error but still this task doesnt serve my purpose of saving/ commiting update chanages in the database.



Thanks,

Prashant

View 3 Replies View Related

Sql2005:Cannot Use SAVE TRANSACTION Within A Distributed Transaction

Oct 10, 2005

Error returned when trying to commit the transaction to a database that is a replication distributor. (sql2005 ctp16)

View 10 Replies View Related

Problem With SSIS Transaction...Transaction Scope

Jun 1, 2006



Hi,

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

View 12 Replies View Related

New Transaction Cannot Enlist In The Specified Transaction Coordinator

Nov 28, 2004

I'm getting this error:

The operation could not be performed because the OLE DB provider 'SQLOLEDB' was unable to begin a distributed transaction.
[OLE/DB provider returned message: New transaction cannot enlist in the specified transaction coordinator. ]
OLE DB error trace [OLE/DB Provider 'SQLOLEDB' ITransactionJoin::JoinTransaction returned 0x8004d00a].

http://support.microsoft.com/kb/839279 this didn't help

any suggestions?

View 3 Replies View Related

BEGIN TRANSACTION And COMMIT TRANSACTION

Oct 11, 2000

I am executing a stored procedure something like this

Create Procedure TEST
@test1
@test2
AS
BeGIN TRANSACTION ONE
SELECT...
UPDATE..
....
....

....
TRUNCATE
etc and lot of Select,update and delete statements like this
.....
COMMIT TRANSACTION ONE


The Block of code which I have b/w BEGIN TRANSACTION AND COMMIT TRANSACTION ..Will it be rolled back
if it encounters any errors in the SELECT,UPPDATE,DELETE ..statements which I have with the transaction one.
IF not How do I roll back if it encounters any erros b/w the BEGIN TRANSACTION and END TRANSACTION.

Thanks
micky

View 1 Replies View Related

New Transaction Cannot Enlist In Transaction Coordinator (was Please Help...)

Apr 18, 2005

Hi all,

In my ASP application, I've been using this code:

----------------------------------------------
dim conn, connectionstring

connectionstring= "Provider=SQLOLEDB.1; Data Source = blahblah; Initial Catalog = abc; User Id = osss; Password=xxx"

set conn = server.CreateObject("adodb.connection")
conn.open connectionstring

----------------------------------------------

It's just basically to set up the connection to the SQL server, it works on my other pages, but on a few pages, the last line (conn.open connectionstring) triggers this error:

"Microsoft OLE DB Provider for SQL Server error '8004d00a'

New transaction cannot enlist in the specified transaction coordinator. "

I've never encountered this error before and I couldn't think of any solution... please help!!!

Thanks so much,
Annie

View 2 Replies View Related

BEGIN TRANSACTION COMMIT TRANSACTION Help

Sep 24, 2007

I had thought that if any statement failed within a BEING TRANS .. COMMIT TRANS block, then all the statements would be rolled back. But I am seeing different behavior (SQL Server 2000 8.00.2039)

For instance, run these statements to set up a test:
--DROP TABLE testTable1
--DROP TABLE testTable2
CREATE TABLE testTable1 (f1 varchar(1))
CREATE TABLE testTable2 (f1 varchar(1))
CREATE UNIQUE INDEX idx_tmptmp ON testTable1 (f1)
insert into testTable1(f1) values ('a')

So table testTable1 has a unique index on it..

Now try to run these statements:

--DELETE FROM testTable2
BEGIN TRANSACTION
insert into testTable1(f1) values ('a')
insert into testTable2(f1) values ('a')
COMMIT TRANSACTION

SELECT * FROM testTable2


..the first insert fails on the unique index.. but the second insert succeeds. Shouldn't the second insert roll back? How can I make two operations atomic?

View 8 Replies View Related

Why Transaction Gets Promoted To Distributed Transaction

Feb 1, 2007

Hi,On My local SQL server I have added a linked server to another SQLserver (remoteserver) in another Windows NT Domain.When I run this codeselect count(*) from remoteserver.mosaics.dbo.LocationThis works fine.However when I usebegin transactionselect count(*) from remoteserver.mosaics.dbo.LocationIt errors out saying thatThe operation could not be performed because the OLE DB provider'SQLOLEDB' was unable to begin a distributed transaction.New transaction cannot enlist in the specified transactioncoordinator. ]OLE DB error trace [OLE/DB Provider 'SQLOLEDB'ITransactionJoin::JoinTransaction returned 0x8004d00a].My question is even though I am just reading data from theremoteserver, why does the local transaction get promoted to adistributed transaction.Any help will be grately appreciated.TIA...Rohit

View 2 Replies View Related

New Transaction Cannot Enlist In The Specified Transaction Coordinator

May 18, 2007

Hi



I am trying transfer data from Back Office Server to Head Office using DTS. It is failing in few stores, rest of the store it is OK

Configuration

Head office :Windows 2003 SP1 and Sql Server 2000 SP3

Failing Store:Windows 2003 SP2 and SQL SERVER 2005

Successful Store :Windows 2003 SP2 qnd SQL SERVER 2000





At Store: Setting for MSDTC

Log on Account for MSDTC Service : Network Service

Network DTC Access = True

Allow Inbound = True

Allow Outbound = True

No Authentication Required = True

TurnOffRPCSecurity = 1

port Ranges for RPC = 5000- 5100



The error Message is as follows:

(Microsoft Data Transformation Services (DTS) Package (8004d00a): Connection 'Head Office SQL Server' for Task 'DTSTask_DTSDataPumpTask_1' does not support joining distributed transactions or failed when attempting to join. Unable to enlist in the transaction.
) (Microsoft OLE DB Provider for SQL Server (8004d00a): New transaction cannot enlist in the specified transaction coordinator. )



If any one can help me, that will be great!!! Thanks in advance



Shiny

View 3 Replies View Related

Transaction Count After EXECUTE Indicates That A COMMIT Or ROLLBACK TRANSACTION Statement Is Missing. Previous Count = 1, Current Count = 0.

Aug 6, 2006

With the function below, I receive this error:Error:Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 1, current count = 0.Function:Public Shared Function DeleteMesssages(ByVal UserID As String, ByVal MessageIDs As List(Of String)) As Boolean        Dim bSuccess As Boolean        Dim MyConnection As SqlConnection = GetConnection()        Dim cmd As New SqlCommand("", MyConnection)        Dim i As Integer        Dim fBeginTransCalled As Boolean = False
        'messagetype 1 =internal messages        Try            '            ' Start transaction            '            MyConnection.Open()            cmd.CommandText = "BEGIN TRANSACTION"            cmd.ExecuteNonQuery()            fBeginTransCalled = True            Dim obj As Object            For i = 0 To MessageIDs.Count - 1                bSuccess = False                'delete userid-message reference                cmd.CommandText = "DELETE FROM tblUsersAndMessages WHERE MessageID=@MessageID AND UserID=@UserID"                cmd.Parameters.Add(New SqlParameter("@UserID", UserID))                cmd.Parameters.Add(New SqlParameter("@MessageID", MessageIDs(i).ToString))                cmd.ExecuteNonQuery()                'then delete the message itself if no other user has a reference                cmd.CommandText = "SELECT COUNT(*) FROM tblUsersAndMessages WHERE MessageID=@MessageID1"                cmd.Parameters.Add(New SqlParameter("@MessageID1", MessageIDs(i).ToString))                obj = cmd.ExecuteScalar                If ((Not (obj) Is Nothing) _                AndAlso ((TypeOf (obj) Is Integer) _                AndAlso (CType(obj, Integer) > 0))) Then                    'more references exist so do not delete message                Else                    'this is the only reference to the message so delete it permanently                    cmd.CommandText = "DELETE FROM tblMessages WHERE MessageID=@MessageID2"                    cmd.Parameters.Add(New SqlParameter("@MessageID2", MessageIDs(i).ToString))                    cmd.ExecuteNonQuery()                End If            Next i
            '            ' End transaction            '            cmd.CommandText = "COMMIT TRANSACTION"            cmd.ExecuteNonQuery()            bSuccess = True            fBeginTransCalled = False        Catch ex As Exception            'LOG ERROR            GlobalFunctions.ReportError("MessageDAL:DeleteMessages", ex.Message)        Finally            If fBeginTransCalled Then                Try                    cmd = New SqlCommand("ROLLBACK TRANSACTION", MyConnection)                    cmd.ExecuteNonQuery()                Catch e As System.Exception                End Try            End If            MyConnection.Close()        End Try        Return bSuccess    End Function

View 5 Replies View Related

Transaction Scope - 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&a

May 15, 2008

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.

View 1 Replies View Related

The Microsoft Distributed Transaction Coordinator (MS DTC) Has Cancelled The Distributed Transaction.

Feb 29, 2008

We have a test db, a staging db and a live db. I have a stored procedure that runs fine on test and staging, but throws the following error on live.


The Microsoft Distributed Transaction Coordinator (MS DTC) has cancelled the distributed transaction.


The stored procedure uses linked servers and a transaction.
We're using the following transaction code in the stored procedure

BEGIN

BEGIN TRANSACTION

BEGIN TRY

---
procedure stuff here
---
COMMIT TRANSACTION
END TRY



BEGIN CATCH

DECLARE @ErrorSeverity INT, @ErrorNumber INT, @ErrorMessage NVARCHAR(4000), @ErrorState INT

SET @ErrorSeverity = ERROR_SEVERITY()

SET @ErrorNumber = ERROR_NUMBER()

SET @ErrorMessage = ERROR_MESSAGE()

SET @ErrorState = ERROR_STATE()



IF @ErrorState = 0

SET @ErrorState = 1



RAISERROR ('ERROR OCCURED:%d', @ErrorSeverity, @ErrorState, @ErrorNumber)

IF XACT_STATE() < 0

ROLLBACK TRANSACTION

END CATCH



END


I found the following link which seems to be the problem we're experiencinghttp://support.microsoft.com/kb/937517

The link includes a workaround which is the following:
"To prevent the SQLNCLI provider from sending an attention signal to the server, use the SQLNCLI provider to consume fully any rowsets that the OLE DB consumer creates. "


How do I use the SQLNCLI provider to fully consume any rowsets?

View 11 Replies View Related

Begin And End Transaction And Transaction Log

Dec 12, 2007

Hello everyone,This is more of an architectural question about SQL Server. Cansomeone please explain why when I perform a query such as the onebelow that updates a table using begin and end transaction I am unableto programmatically truncate the transaction log. The only way I havefound to truncate the transaction log is to stop and start the SQLServer Service. Does this transaction use the tempdb? Is that why Iam unable to truncate the transaction log? Is there a better way todo this?Begin trans T1Update sometableSet random_row = 'blah'End trans T1Thanks!

View 5 Replies View Related

Get The Current Transaction ID During The Transaction

Jan 15, 2008

Hi Everyone-
i wonder how can i get the current transaction ID during the running of transaction

thanx
Maylo

View 3 Replies View Related

Transaction/statement Not To Log To Transaction Log ?

Sep 20, 2007

Hi There

I have a large database in full recovery model (9.0.3152).

I have s stored procedure, that generates a HUGE transaction log, i have optimized the stored proc as much as i can, i have also broken it up into smaller transactions that i commit more frequently and do transaction log backups more frequently.

However i cannot make a significant dent into the transaction log size.

Is there anyway / syntax to ensure that a transaction or statement is not logged to the transaction log ?

I will never want to have this transaction or commands present if i do a restore.

Is this possible ?

Thanx

View 5 Replies View Related

Is The Transaction Context Available Within A 'called' Stored Procedure For A Transaction That Was Started In Parent Stored Procedure?

Mar 31, 2008

I have  a stored procedure 'ChangeUser' in which there is a call to another stored procedure 'LogChange'. The transaction is started in 'ChangeUser'. and the last statement in the transaction is 'EXEC LogChange @p1, @p2'. My questions is if it would be correct to check in 'LogChange' the following about this transaction: 'IF @@trancount >0 BEGIN Rollback tran' END Else BEGIN Commit END.
 Any help on this would be appreciated.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved