I did check this but the problem doesn't appears to be with mismatch of type.
I'm trying to use CLR to convert back a file from blob data. Below is the c# code converted to dll and stored using assembly.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlTypes;
using System.IO;
using Microsoft.SqlServer.Server;
namespace CLRProcedures
{
public class WriteFile
{
[SqlFunction]
public static SqlInt32 WriteToFile(SqlBytes binary, SqlString path, SqlBoolean append)
{
try
{
if (!binary.IsNull && !path.IsNull && !append.IsNull)
{
var dir = Path.GetDirectoryName(path.Value);
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
using (var fs = new FileStream(path.Value, append ? FileMode.Append : FileMode.OpenOrCreate))
{
byte[] byteArr = binary.Value;
for (int i = 0; i < byteArr.Length; i++)
{
fs.WriteByte(byteArr[i]);
};
}
return 1;
}
else
return 0;
}
catch (Exception ex)
{
return -2;
}
}
}
}
SQL queries are as below :
CREATE ASSEMBLY FileOutput from 'c:\dlls\CLRProcedures.dll' WITH PERMISSION_SET = SAFE
CREATE PROCEDURE FileOutput
@file varbinary(max),
@filepath nvarchar(4000),
@append bit,
@message int OUTPUT
AS
EXTERNAL NAME FileOutput.[CLRProcedures.WriteFile].WriteToFile
This throws error : 'CREATE PROCEDURE failed because parameter counts do not match.'
I've re-verified from here if there is type mismatch but there isnt one. Where could I be going wrong ? I tried to change the return type of c# code but same issue.
Thank you
@message int OUTPUTparameter?outputis not the same as return value;outputis kinda likerefin .NET