Я не могу придумать более простой способ сделать это, чем отбросить бит C # ...
static void Main(string[] args)
{
GetBinaryDataToFile("Server=localhost;Initial Catalog=ReportServer;Integrated Security=true", "D:\\temp.dat");
}
public static void GetBinaryDataToFile(string connectionString, string path)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT Sid FROM Users WHERE UserID = '62066184-8403-494E-A571-438ABF938A4F'";
command.CommandType = CommandType.Text;
using (SqlDataReader dataReader = command.ExecuteReader())
{
if (dataReader.Read())
{
SqlBinary sqlBinary = dataReader.GetSqlBinary(0);
File.WriteAllBytes(path, sqlBinary.Value);
}
dataReader.Close();
}
}
connection.Close();
}
}
Этот код был протестирован с использованием столбца Users.Sid (который имеет varbinaryвведите) в стандартной установке SQL Server с службами отчетов.