I want synchronize data between two SQL servers 2008 Express Edition. I would like to avoid escalating SQL queries to MS DTC service (MS DTC service is not running). For synchronization I use stored procedures without transactions.
I have more stored procedure. The procedures which download data from linked server and then store it to local DB works fine.
I am using stored procedures to upload data to linked server. Inside stored procedure I have no transaction used.
When I run stored procedure from SQL Management Studio, data are correctly uploaded to server. But when I call this procedure from .NET 4.0 C# code, it ends up with error
8501 - MSDTC on server 'compName\SQLEXPRESS2008' is unavailable.
No transactions used within application code. Sometimes the data is uploaded even from the code. I cannot figure out when the MSDTC is necessary and when not.
Why is MSDTC needed when no transaction used?
EDIT1:
I have little progress. This code is used for calling stored procedure. First time when the procedure is called, the data is correctly uploaded to server. Next time it ends with exception 8501.
SqlCommand sqlCmd = new SqlCommand("spUploadUnsendStockDocument");
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddWithValue("@pDebug", false);
sqlCmd.Parameters.AddWithValue("@boxId", boxId);
// Return value as parameter
SqlParameter returnValue = new SqlParameter("returnVal", SqlDbType.Int);
returnValue.Direction = ParameterDirection.ReturnValue;
sqlCmd.Parameters.Add(returnValue);
try
{
using (SqlConnection conn = new SqlConnection(dbConnection.ConnectionString))
{
conn.Open();
sqlCmd.Connection = conn;
sqlCmd.ExecuteScalar();
sqlCmd.Dispose();
conn.Close();
}
if (Convert.ToInt16(returnValue.Value) == 1)
LogError("error while sending");
return Convert.ToInt16(returnValue.Value) == 0;
}
catch (Exception ex)
{
Log(ex);
return false;
}