Search code examples
sql-serverwcfstored-proceduresmsdtc

MSDTC on server '' is unavailable. sql server link server error when call stored procedure


I have 3 servers with these names ServiceServer, DatabaseServer and WarehouseServer.

I have a WCF service on ServiceServer that calls a stored procedure in DatabaseServer.

public async void UpdateStatus(NajaResult najaresult, string userid, string IsWorn, string FuelSystem, string ValidTest, string SymfaServiceStatus, string NajaServiceStatus)
{
    string _FuelSystem = (string.IsNullOrEmpty(FuelSystem)) ? "2" : FuelSystem;
    _ctx.Database.ExecuteSqlCommand("EXEC [dbo].[UpdateInquiryStatus] @userid='" + userid + "', @IsWorn='" + IsWorn + "',@FuelSystem='" + _FuelSystem + "',@ValidTest='" + ValidTest + "',@SymfaServiceStatus='" + SymfaServiceStatus + "',@NajaServiceStatus='" + NajaServiceStatus + "' ,"
+ "@Chassis='" + najaresult.Chassis + "',@CarColor=N'" + najaresult.CarColor + "',@MotorNum='" + najaresult.MotorNum + "' ,@Vin='" + najaresult.VinNo + "', @SystemType=N'" + najaresult.SystemType + "',@CarTipe=N'" + najaresult.CarTip + "',@FuelType='" + najaresult.FuelType + "',@Model='" + najaresult.CarModel + "'" + ",@CarType=N'" + najaresult.CarType + "'");
}

Here is my stored procedure UpdateInquiryStatus that is located in DatabaseServer:

ALTER PROCEDURE [dbo].[UpdateInquiryStatus]
    @userid nvarchar(max),
    @IsWorn nvarchar(max),
    @FuelSystem nvarchar(max),
    @ValidTest nvarchar(max),
    @SymfaServiceStatus nvarchar(max),
    @NajaServiceStatus nvarchar(max),
    @Vin nvarchar(max),
    @SystemType nvarchar(max),
    @CarTipe nvarchar(max),
    @FuelType nvarchar(max),
    @Model nvarchar(max),
    @Chassis nvarchar(max),
    @CarColor nvarchar(max),
    @MotorNum nvarchar(max),
    @CarType nvarchar(max)
AS   
    INSERT INTO [PRISYMFA22a1\MASSYMSQLSERVER].[DB].[dbo].AutomotiveTemps 
           (id, isworn, validtest, CarColor, CarTipe, CarType, Chassis, 
            FuelSystem, FuelType, Model, MotorNum, SubmitDatetime, 
            SystemType, UserId, VIN)
    VALUES (NEWID(), @IsWorn, @ValidTest, @CarColor, @CarTipe, @CarType, @Chassis,
            @FuelSystem, @FuelType, @Model, @MotorNum, GETDATE(),
            @SystemType, @userid, @Vin)

As a note I created a link server between DatabaseServer and WarehouseServer.

As you can, see my procedure inserts a record into WarehouseServer but I get this error :

MSDTC on server 'DatabaseServer' is unavailable.

but my msdtc is running and all firewalls are disabled. I opened all inbound and outbound remote in component service too. But same error is being returned


Solution

  • Go to Component Services on DatabaseServer and navigate down to Local DTC, right-click and select properties.

    On the Security tab make sure Network DTC Access is checked and Allow Remote Clients.

    Check Allow Inbound (and maybe Outbound) under Transaction Manager Communication and you may need to alter the Authentication depending on which versions of Windows you are running on both DatabaseServer and ServiceServer.