473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Distributed SQL Transaction???

45
Hi all,

I am writing a stand alone app. in C#. In this app I need to read some values from a database on server A and Insert these values in another database on server B.

I have a number of INSERT statements. I want to group them all in a transaction so that if anyone of them fails the transaction can be rolled back.

It looks something like this.

SqlConnection RmtSrv = new SqlConnection();
RmtSrv.ConnectionString = "Data Source = server B; " +
"Initial Catalog = master;" +
"User id = **;" +
"Password = ***;";
RmtSrv.Open();
SqlCommand SqlCmd = new SqlCommand("EXEC Master.dbo.xp_servicecontrol " +
"'QUERYSTATE', 'MSDTC'",RmtSrv);
SqlDataReader SqlRead = SqlCmd2.ExecuteReader();
SqlRead.Read();
string sMSDTCStatus = SqlRead.GetValue(0).ToString(); //string to collect the current state of the MSDTC.
SqlRead.Close();

if (sMSDTCStatus == "Stopped.")
{
MessageBox.Show("MsDTC current state - Stopped. \nTo start MSDTC click OK.");
SqlCmd.CommandText = ("EXEC Master.dbo.xp_servicecontrol " +
"'START', 'MSDTC'");
SqlCmd.ExecuteNonQuery();
}
RmtSrv.Close();

//
SqlTransaction trans;
trans = connForServerA.BeginTransaction();

try
{
new SqlCommand("SQL INSERT 1", connForServerA, trans).ExecuteNonQuery();
new SqlCommand("SQL INSERT 1", connForServerA, trans).ExecuteNonQuery();
trans.Commit();
}
catch(Exception e)
{
MessageBox.Show(e.Message);
trans.Rollback();
}


Yes, I have linked servers. In the insert statements I Select the values from one database table and Insert them into another database on a different server like this.

INSERT INTO [SERVER_B].[DatabaseName].dbo.tableName
(COL1, COL2, COL3)
SELECT COL1, COL2, COL3 FROM tableName(This is on server_A)

But this doesnot work.

Any suggestions.
Apr 25 '07 #1
0 806

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Steve Thorpe | last post by:
Hi have have two linked SQL Servers and I am trying to get things working smootly/quickly. Should I be using 'BEGIN TRANSACTION' or 'BEGIN DISTRIBUTED TRANSACTION' ? Basicly, these SPs update...
7
by: Richard Maher | last post by:
Hi, I am seeking the help of volunteers to test some software that I've developed which facilitates distributed two-phase commit transactions, encompassing any resource manager (e.g. SQL/Server...
0
by: DotNetJunkies User | last post by:
I am writing a distributed transaction code. My current scenario include a client database(Suppose client- having 4 main database) which can be installed anywhere which would connect to a public...
1
by: Avanish Pandey | last post by:
Hello All We have 3 differen services (in 3 different server) Service A,B,C . We want to implement distributed transaction when call methods of B and C from A. Is it possible? if yes then how? ...
0
by: Manoj Sharma | last post by:
I am performance testing some batch processing engines. These are written in ..NET and SQL Server and are typically concerned with generating XML files out of data retrieved from the database. I...
2
by: Jo Siffert | last post by:
Hi all, I would like to perform an INSERT INTO LINKEDSVR.dbo.xyz.abc SELECT ... FROM dbo.dfg where LINKEDSVR is a linked server on another machine. Both servers are running SQLServer 2000...
2
by: John Lee | last post by:
Hi, I have few questions related to .NET 2.0 TransactionScope class behavior: 1. Check Transaction.Current.TransactionInformation.DistributedIdentifier to identify if distributed transaction...
0
by: gshawn3 | last post by:
Hi, I am having a hard time creating a Trigger to update an Oracle database. I am using a SQL Server 2005 Express database on a Win XP Pro SP2 desktop, linked to an Oracle 10g database on a...
2
by: Dan Kelley | last post by:
I have 2 services, ServiceA and ServiceB. Certain user driven functions require ServiceA to perform some DB tasks, before sending a request to ServiceB to perform some additional tasks. If ServiceB...
2
by: rbg | last post by:
Hi, On My local SQL server I have added a linked server to another SQL server (remoteserver) in another Windows NT Domain. When I run this code select count(*) from...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.