May 13, 2019

WCF Service Project publish fails due to .datasource files.

I have multiple WCF service projects in solution file. One service (User Management) has reference to another service (CommonLib) to reuse common functionality. For service method calls I have created separate interfaces and hence separate class templates for each method's request. The parameters of methods are encapsulated in single request object as public properties. And similar pattern used to methods' return values or responses.

In some cases, the request classes names become too long (for some reasons) and that causes me the issue when publishing my User Management WCF service. It was build successfully, but when try to publish, it was showing the following error message:

Copying file Service References\CoreSystem.B2B\CoreService.CoreSystemIntegration.CoreSystem.B2B.GetCompanyConsentsByCompanyAccountIDResponse.datasource to obj\Release\AspnetCompileMerge\Source\Service References\CoreSystem.B2B\CoreService.CoreSystemIntegration.CoreSystem.B2B.GetCompanyConsentsByCompanyAccountIDResponse.datasource failed. The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

While searching I found different suggestions which give valuable information on the topic:

In my case I fixed the issue by deleting all the .datasource files from ProjectRoot/Properties/DataSources folder.

After deleting .datasource files, I got my WCF service published successfully.

May 12, 2019

ExecuteNonQuery() always returns -1

I created the following simple SP to update table record. While running this SP from C#, the ExecuteNonQuery() method was constantly returning -1.

CREATE PROCEDURE [dbo].[UpdateCategory]
  @CategoryID int
 ,@CategoryCode varchar(10)
 ,@CategoryName varchar(50)
 ,@CategoryDescription varchar(100)

AS
BEGIN
 
 SET NOCOUNT ON;

    UPDATE [dbo].[Category]
    SET 
        [CategoryCode] = @CategoryCode
        ,[CategoryName] = @CategoryName
        ,[CategoryDescription] = @CategoryDescription

  WHERE CategoryID = @CategoryID

END

After searching I found the issue was the first line of SP body.

SET NOCOUNT ON;

Setting NOCOUNT ON will stop the number of affect rows to be returned to client. So the default response is always -1.

To get the response with real no of affected rows just remove this line and it will start returning the number of affected rows.