나는 System.Transactions 네임 스페이스를 보았고, 실제로이 네임 스페이스 사용법을 사용하여 RDMBS를 만들 수 있습니까?System.Transactions의 실용적인 용도는 무엇입니까?
하지만 몇 가지 예를 보았을 때 System.Transactions가 간단한 시도를 넘어서 성공/실패 결과를 얻는 것 이외의 다른 방법을 이해하지 못합니다.
이것은 MSDN의 웹 사이트에있는 예제입니다. 매우 간단 할 수 있지만이 샘플의 이점을 이해할 수 없다는 것을 알고 있습니다. 다음 예제에서 간단한 try/catch와 Transaction scope의 차이점을 말해 줄 수 있습니까? .
RDBMS (내 자신의 RDMBS 만들기)를 작성해야한다면, 우리는 우리가 실행하는 작업의 디스크에 많은 로그를 작성해야한다는 것을 알고 있으며, 결국에는 롤백의 경우 해당 작업을 실행 취소하지만 여기에는 아무것도 되돌리기위한 것이 없습니다.
// This function takes arguments for 2 connection strings and commands to create a transaction
// involving two SQL Servers. It returns a value > 0 if the transaction is committed, 0 if the
// transaction is rolled back. To test this code, you can connect to two different databases
// on the same server by altering the connection string, or to another 3rd party RDBMS by
// altering the code in the connection2 code block.
static public int CreateTransactionScope(
string connectString1, string connectString2,
string commandText1, string commandText2)
{
// Initialize the return value to zero and create a StringWriter to display results.
int returnValue = 0;
System.IO.StringWriter writer = new System.IO.StringWriter();
try
{
// Create the TransactionScope to execute the commands, guaranteeing
// that both commands can commit or roll back as a single unit of work.
using (TransactionScope scope = new TransactionScope())
{
using (SqlConnection connection1 = new SqlConnection(connectString1))
{
// Opening the connection automatically enlists it in the
// TransactionScope as a lightweight transaction.
connection1.Open();
// Create the SqlCommand object and execute the first command.
SqlCommand command1 = new SqlCommand(commandText1, connection1);
returnValue = command1.ExecuteNonQuery();
writer.WriteLine("Rows to be affected by command1: {0}", returnValue);
// If you get here, this means that command1 succeeded. By nesting
// the using block for connection2 inside that of connection1, you
// conserve server and network resources as connection2 is opened
// only when there is a chance that the transaction can commit.
using (SqlConnection connection2 = new SqlConnection(connectString2))
{
// The transaction is escalated to a full distributed
// transaction when connection2 is opened.
connection2.Open();
// Execute the second command in the second database.
returnValue = 0;
SqlCommand command2 = new SqlCommand(commandText2, connection2);
returnValue = command2.ExecuteNonQuery();
writer.WriteLine("Rows to be affected by command2: {0}", returnValue);
}
}
// The Complete method commits the transaction. If an exception has been thrown,
// Complete is not called and the transaction is rolled back.
scope.Complete();
}
}
catch (TransactionAbortedException ex)
{
writer.WriteLine("TransactionAbortedException Message: {0}", ex.Message);
}
catch (ApplicationException ex)
{
writer.WriteLine("ApplicationException Message: {0}", ex.Message);
}
// Display messages.
Console.WriteLine(writer.ToString());
return returnValue;
}
위의 예에서 우리는 무엇을하고 있습니까? 나는 SQL Client 라이브러리가 모든 것을 올바르게 수행 할 것이라고 추측합니다. 이것은 System.IO.StringWriter가 모든 성공 텍스트 또는 모든 실패 텍스트를 포함한다는 것을 의미합니까? 또는 TransactionScope의 범위 사이에 잠금이 있습니까?
"make a RDBMS"란 무엇을 의미합니까? – nos
관계형 데이터베이스 관리 시스템, SQL Server 또는 MySQL 또는 Oracle의 사본, 내 자신의 XYZSql 데이터베이스 시스템을 .net으로 만들고 싶다면 이것을 사용할 수 있습니까? –
새로운 XYZSql 데이터베이스 시스템이 트랜잭션을 지원하는 경우 실제로는 아니지만 .NET XYZSql ADO.NET 드라이버에서 System.Transactions에 대한 지원을 구현할 수 있습니다. – nos