두 시스템에 SQL Server 2008 R2를 설치했습니다. 하나의 시스템이 서버 역할을하고 다른 하나는 클라이언트 역할을합니다.asp.net의 단일 TransactionScope에서 두 개의 SqlConnection을 사용하는 방법 C#
나는 그것이를 보여줍니다 내가
using (TransactionScope trnsScope = new TransactionScope())
{
try
{
List<Master_ProductBLL> lstProduct = new List<Master_ProductBLL>();
//My First SQL Connection For Server
using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString))
{
connection.Open();
//Here I can get All Products from Server Database
lstProduct = Master_ProductBLL.GetMaster_ProductBLLs(DBAction.Status.Active, "");
connection.Dispose();
}
//My Second SQL Connection For Client
using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection1"].ConnectionString))
{
connection.Open();
//Here I have save my Server Product into Client SQL Server
foreach (Master_ProductBLL item in lstProduct)
{
item.Save(true);
}
connection.Dispose();
}
trnsScope.Complete();
trnsScope.Dispose();
}
catch (TransactionException ex)
{
trnsScope.Dispose();
throw ex;
}
}
코딩
<connectionStrings>
<add name="DBConnection" connectionString="Data Source=SERVER-PC\SQLEXPRESS2008;Initial Catalog=POS;Integrated Security=False;User Id=sa;Password=sql2008;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
<add name="DBConnection1" connectionString="Data Source=CLIENT-PC\SQLEXPRESS2008;Initial Catalog=POS;Integrated Security=False;User Id=sa;Password=sql2008;Connection Timeout=1;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
여기 내 Web.config의에서 클라이언트 시스템 데이터베이스
에 서버 시스템 데이터베이스에서 제품을 복사해야 오류 : MSDTC 켜짐 서버 'CLIENT-PC \ SQLEXPRESS2008'을 사용할 수 없습니다.
서버에 대한 분산 트랜잭션 코디네이터의 주소를 서버에서 가져올 수 없습니다. 서버에서 DTC를 사용할 수 있습니까?
나는 다음과 같은 세부
- 서비스로 이동 그것을 구글하고 찾을 수 있습니다. (START> SETTINGS> CONTROL PANEL> 관리 도구> 서비스)
- 'Distributed Transaction Coordinator'라는 서비스를 찾아서 오른쪽 클릭 (> 선택)> 시작.
- 는이 서비스를 영구적으로
내가 위의 단계 서버와 클라이언트를 모두 수행 한이 문제를 해결하기 위해 자동으로 실행 할 수 있습니다.
그러나 여전히이 두 개 (또는 그 이상)의 SQL 서버가 transactionnaly '동기화'가 될 수 있도록
https://stackoverflow.com/questions/29414250/msdtc-on-server-server-is-unavailable –
있습니다 간단합니다 당신도 똑같은 오류가 발생하고 있습니까? –