public int InsertBinaryProperty(int versionId, int propertyTypeId, BinaryDataValue value, bool isNewNode) { if (value.Stream != null && value.Stream.Length > Int32.MaxValue) { throw new NotSupportedException(); // MS-SQL does not support stream size over [Int32.MaxValue] } SqlProcedure cmd = null; int id; try { cmd = new SqlProcedure { CommandText = (isNewNode ? INSERT_BINARY_PROPERTY : DELETE_AND_INSERT_BINARY_PROPERTY), CommandType = CommandType.Text }; cmd.Parameters.Add("@VersionId", SqlDbType.Int).Value = (versionId != 0) ? (object)versionId : DBNull.Value; cmd.Parameters.Add("@PropertyTypeId", SqlDbType.Int).Value = (propertyTypeId != 0) ? (object)propertyTypeId : DBNull.Value; cmd.Parameters.Add("@ContentType", SqlDbType.VarChar, 50).Value = value.ContentType; cmd.Parameters.Add("@FileNameWithoutExtension", SqlDbType.VarChar, 450).Value = value.FileName.FileNameWithoutExtension == null ? DBNull.Value : (object)value.FileName.FileNameWithoutExtension; cmd.Parameters.Add("@Extension", SqlDbType.VarChar, 50).Value = ValidateExtension(value.FileName.Extension); cmd.Parameters.Add("@Size", SqlDbType.BigInt).Value = value.Size; cmd.Parameters.Add("@Checksum", SqlDbType.VarChar, 200).Value = (value.Checksum != null) ? (object)value.Checksum : DBNull.Value; if (value.Stream != null && value.Stream.Length > 0) { var streamSize = Convert.ToInt32(value.Stream.Length); var buffer = new byte[streamSize]; value.Stream.Seek(0, SeekOrigin.Begin); value.Stream.Read(buffer, 0, streamSize); cmd.Parameters.Add(new SqlParameter("@Value", SqlDbType.VarBinary)).Value = buffer; } else { cmd.Parameters.Add(new SqlParameter("@Value", SqlDbType.VarBinary)).Value = DBNull.Value; } id = Convert.ToInt32(cmd.ExecuteScalar(), CultureInfo.CurrentCulture); } finally { if (cmd != null) { cmd.Dispose(); } } return(id); }
public int InsertBinaryPropertyOld(int versionId, int propertyTypeId, BinaryDataValue value) { if (value.Stream != null && value.Stream.Length > Int32.MaxValue) { throw new NotSupportedException(); // MS-SQL does not support stream size over [Int32.MaxValue] } SqlProcedure cmd = null; //object pointer; int id = 0; try { cmd = new SqlProcedure { CommandText = "proc_BinaryProperty_Insert" }; cmd.Parameters.Add("@VersionId", SqlDbType.Int).Value = (versionId != 0) ? (object)versionId : DBNull.Value; cmd.Parameters.Add("@PropertyTypeId", SqlDbType.Int).Value = (propertyTypeId != 0) ? (object)propertyTypeId : DBNull.Value; cmd.Parameters.Add("@ContentType", SqlDbType.VarChar, 50).Value = value.ContentType; cmd.Parameters.Add("@FileNameWithoutExtension", SqlDbType.VarChar, 450).Value = value.FileName.FileNameWithoutExtension == null ? (object)DBNull.Value : (object)value.FileName.FileNameWithoutExtension; cmd.Parameters.Add("@Extension", SqlDbType.VarChar, 50).Value = ValidateExtension(value.FileName.Extension); cmd.Parameters.Add("@Size", SqlDbType.BigInt).Value = value.Size; cmd.Parameters.Add("@Checksum", SqlDbType.VarChar, 200).Value = (value.Checksum != null) ? (object)value.Checksum : DBNull.Value;; //SqlParameter pointerParameter = cmd.Parameters.Add("@Pointer", SqlDbType.Binary, 16); //pointerParameter.Direction = ParameterDirection.Output; id = Convert.ToInt32(cmd.ExecuteScalar(), CultureInfo.CurrentCulture); //pointer = pointerParameter.Value; } finally { cmd.Dispose(); } if (value.Stream != null && value.Stream.Length > 0) { // Stream exists -> write it WriteBinaryStream(value.Stream, id); } return(id); }
internal static byte[] ReadRandom(BlobStorageContext context, long offset, int count) { var commandText = LoadBinaryFragmentScript; byte[] result; using (var cmd = new SqlProcedure { CommandText = commandText }) { cmd.Parameters.Add("@FileId", SqlDbType.Int).Value = context.FileId; cmd.Parameters.Add("@Position", SqlDbType.BigInt).Value = offset + 1; cmd.Parameters.Add("@Count", SqlDbType.Int).Value = count; cmd.CommandType = CommandType.Text; result = (byte[])cmd.ExecuteScalar(); } return(result); }
/// <summary> /// Returns whether the FileStream feature is enabled in the blob provider or not. /// </summary> /// <returns></returns> public bool IsFilestreamEnabled() { bool fsEnabled; const string sql = "SELECT COUNT(name) FROM sys.columns WHERE Name = N'FileStream' and Object_ID = Object_ID(N'Files')"; using (var pro = new SqlProcedure { CommandText = sql, CommandType = CommandType.Text }) { try { fsEnabled = Convert.ToInt32(pro.ExecuteScalar()) > 0; } catch (Exception ex) { SnLog.WriteException(ex); fsEnabled = false; } } return(fsEnabled); }
/// <summary> /// Inserts a new binary record into the metadata database containing an already exising file id, /// removing the previous record if the content is not new. /// </summary> /// <param name="value">Binary data to insert.</param> /// <param name="versionId">Content version id.</param> /// <param name="propertyTypeId">Binary property type id.</param> /// <param name="isNewNode">Whether this value belongs to a new or an existing node.</param> public void InsertBinaryPropertyWithFileId(BinaryDataValue value, int versionId, int propertyTypeId, bool isNewNode) { SqlProcedure cmd = null; int id; try { cmd = new SqlProcedure { CommandText = isNewNode ? InsertBinaryPropertyWithKnownFileIdScript : DeleteAndInsertBinaryPropertyWithKnownFileId, CommandType = CommandType.Text }; cmd.Parameters.Add("@VersionId", SqlDbType.Int).Value = versionId != 0 ? (object)versionId : DBNull.Value; cmd.Parameters.Add("@PropertyTypeId", SqlDbType.Int).Value = propertyTypeId != 0 ? (object)propertyTypeId : DBNull.Value; cmd.Parameters.Add("@FileId", SqlDbType.Int).Value = value.FileId; id = (int)cmd.ExecuteScalar(); } finally { cmd?.Dispose(); } value.Id = id; }
protected internal override string LoadTextPropertyValue(int versionId, int propertyTypeId) { SqlProcedure cmd = null; try { cmd = new SqlProcedure { CommandText = "proc_TextProperty_LoadValue" }; cmd.Parameters.Add("@VersionId", SqlDbType.Int).Value = versionId; cmd.Parameters.Add("@PropertyTypeId", SqlDbType.Int).Value = propertyTypeId; var s = (string)cmd.ExecuteScalar(); return s; } finally { cmd.Dispose(); } }
protected internal override int InstanceCount(int[] nodeTypeIds) { var sql = new StringBuilder("SELECT COUNT(*) FROM Nodes WHERE NodeTypeId"); if (nodeTypeIds.Length == 1) sql.Append(" = ").Append(nodeTypeIds[0]); else sql.Append(" IN (").Append(String.Join(", ", nodeTypeIds)).Append(")"); var cmd = new SqlProcedure { CommandText = sql.ToString(), CommandType = CommandType.Text }; ; try { var count = (int)cmd.ExecuteScalar(); return count; } finally { cmd.Dispose(); } }
//====================================================== Powershell provider protected internal override int InitializeStagingBinaryData(int versionId, int propertyTypeId, string fileName, long fileSize) { var sql = @" INSERT INTO StagingBinaryProperties ( VersionId, PropertyTypeId, ContentType, FileNameWithoutExtension, Extension, Size, Stream) VALUES (@VersionId, @PropertyTypeId, @ContentType, @FileNameWithoutExtension, @Extension, @Size, 0x00) SELECT @@IDENTITY"; using (var cmd = new SqlProcedure { CommandText = sql, CommandType = CommandType.Text }) { var fName = Path.GetFileNameWithoutExtension(fileName); var ext = Path.GetExtension(fileName); var mime = MimeTable.GetMimeType(ext.ToLower(CultureInfo.InvariantCulture)); cmd.Parameters.Add(new SqlParameter("@VersionId", SqlDbType.Int)).Value = versionId; cmd.Parameters.Add(new SqlParameter("@PropertyTypeId", SqlDbType.Int)).Value = propertyTypeId; cmd.Parameters.Add(new SqlParameter("@ContentType", SqlDbType.VarChar, 50)).Value = mime; cmd.Parameters.Add(new SqlParameter("@FileNameWithoutExtension", SqlDbType.NVarChar, 450)).Value = fName; cmd.Parameters.Add(new SqlParameter("@Extension", SqlDbType.NVarChar, 450)).Value = ext; cmd.Parameters.Add(new SqlParameter("@Size", SqlDbType.BigInt)).Value = fileSize; var result = cmd.ExecuteScalar(); return Convert.ToInt32(result); } }
public override int GetLastActivityId() { using (var cmd = new SqlProcedure { CommandText = GETLASTACTIVITYIDSCRIPT, CommandType = CommandType.Text }) { var x = cmd.ExecuteScalar(); if (x == DBNull.Value) return 0; return Convert.ToInt32(x); } }
public override string GetNameOfLastNodeWithNameBase(int parentId, string namebase, string extension) { var cmd = new SqlProcedure { CommandText = "SELECT TOP 1 Name FROM Nodes WHERE ParentNodeId=@ParentId AND Name LIKE @Name+'(%)' + @Extension ORDER BY LEN(Name) DESC, Name DESC", CommandType = CommandType.Text }; cmd.Parameters.Add("@ParentId", SqlDbType.Int).Value = parentId; cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = namebase; cmd.Parameters.Add("@Extension", SqlDbType.NVarChar).Value = extension; try { var lastName = (string)cmd.ExecuteScalar(); return lastName; } finally { if (cmd != null) cmd.Dispose(); } }
public int InsertBinaryProperty(int versionId, int propertyTypeId, BinaryDataValue value, bool isNewNode) { if (value.Stream != null && value.Stream.Length > Int32.MaxValue) throw new NotSupportedException(); // MS-SQL does not support stream size over [Int32.MaxValue] SqlProcedure cmd = null; int id; try { cmd = new SqlProcedure { CommandText = (isNewNode ? INSERT_BINARY_PROPERTY : DELETE_AND_INSERT_BINARY_PROPERTY), CommandType = CommandType.Text }; cmd.Parameters.Add("@VersionId", SqlDbType.Int).Value = (versionId != 0) ? (object)versionId : DBNull.Value; cmd.Parameters.Add("@PropertyTypeId", SqlDbType.Int).Value = (propertyTypeId != 0) ? (object)propertyTypeId : DBNull.Value; cmd.Parameters.Add("@ContentType", SqlDbType.VarChar, 50).Value = value.ContentType; cmd.Parameters.Add("@FileNameWithoutExtension", SqlDbType.VarChar, 450).Value = value.FileName.FileNameWithoutExtension == null ? DBNull.Value : (object)value.FileName.FileNameWithoutExtension; cmd.Parameters.Add("@Extension", SqlDbType.VarChar, 50).Value = ValidateExtension(value.FileName.Extension); cmd.Parameters.Add("@Size", SqlDbType.BigInt).Value = value.Size; cmd.Parameters.Add("@Checksum", SqlDbType.VarChar, 200).Value = (value.Checksum != null) ? (object)value.Checksum : DBNull.Value; if (value.Stream != null && value.Stream.Length > 0) { var streamSize = Convert.ToInt32(value.Stream.Length); var buffer = new byte[streamSize]; value.Stream.Seek(0, SeekOrigin.Begin); value.Stream.Read(buffer, 0, streamSize); cmd.Parameters.Add(new SqlParameter("@Value", SqlDbType.VarBinary)).Value = buffer; } else { cmd.Parameters.Add(new SqlParameter("@Value", SqlDbType.VarBinary)).Value = DBNull.Value; } id = Convert.ToInt32(cmd.ExecuteScalar(), CultureInfo.CurrentCulture); } finally { if (cmd != null) cmd.Dispose(); } return id; }
protected internal override int GetUserIdByUploadGuid(Guid uploadGuid) { SqlProcedure cmd = null; int result; try { cmd = new SqlProcedure { CommandText = "proc_ApplicationMessaging_GetUserIdByUploadGuid" }; cmd.Parameters.Add("@Token", SqlDbType.UniqueIdentifier).Value = uploadGuid; result = (int)cmd.ExecuteScalar(); } finally { cmd.Dispose(); } return result; }
protected override int VersionCount(string path) { var proc = new SqlProcedure(); proc.CommandType = CommandType.Text; if (String.IsNullOrEmpty(path) || path == RepositoryPath.PathSeparator) { proc.CommandText = "SELECT COUNT(*) FROM Versions V JOIN Nodes N ON N.NodeId = V.NodeId"; } else { proc.CommandText = "SELECT COUNT(*) FROM Versions V JOIN Nodes N ON N.NodeId = V.NodeId WHERE N.Path LIKE @Path + '/%'"; proc.Parameters.Add("@Path", SqlDbType.NVarChar, 450).Value = path; } return (int)proc.ExecuteScalar(); }
protected internal override long GetTreeSize(string path, bool includeChildren) { SqlProcedure cmd = null; long result; try { cmd = new SqlProcedure { CommandText = "proc_Node_GetTreeSize" }; cmd.Parameters.Add("@NodePath", SqlDbType.NVarChar, 450).Value = path; cmd.Parameters.Add("@IncludeChildren", SqlDbType.TinyInt).Value = includeChildren ? 1 : 0; var obj = cmd.ExecuteScalar(); result = (obj == DBNull.Value) ? 0 : (long)obj; } catch (Exception ex) { throw ex; } finally { if (cmd != null) cmd.Dispose(); } if (result == -1) throw new ApplicationException(); return result; }
protected internal override bool HasChild(int nodeId) { SqlProcedure cmd = null; int result; try { cmd = new SqlProcedure { CommandText = "proc_Node_HasChild" }; cmd.Parameters.Add("@NodeId", SqlDbType.Int).Value = nodeId; result = (int)cmd.ExecuteScalar(); } finally { cmd.Dispose(); } if (result == -1) throw new ApplicationException(); return result > 0; }
/// <summary> /// Updates an existing binary property value in the database and the blob storage. /// </summary> /// <param name="blobProvider">Blob storage provider.</param> /// <param name="value">Binary data to update.</param> public void UpdateBinaryProperty(IBlobProvider blobProvider, BinaryDataValue value) { var streamLength = value.Stream?.Length ?? 0; if (blobProvider != BlobStorageBase.BuiltInProvider && streamLength > 0) { var ctx = new BlobStorageContext(blobProvider, value.BlobProviderData) { VersionId = 0, PropertyTypeId = 0, FileId = value.FileId, Length = streamLength, UseFileStream = false }; blobProvider.Allocate(ctx); using (var stream = blobProvider.GetStreamForWrite(ctx)) value.Stream?.CopyTo(stream); value.BlobProviderName = ctx.Provider.GetType().FullName; value.BlobProviderData = BlobStorageContext.SerializeBlobProviderData(ctx.BlobProviderData); } else { value.BlobProviderName = null; value.BlobProviderData = null; } if (blobProvider == BlobStorageBase.BuiltInProvider && !BlobStorage.FileStreamEnabled) { // MS-SQL does not support stream size over [Int32.MaxValue], // but check only if Filestream is not enabled if (streamLength > int.MaxValue) { throw new NotSupportedException(); } } var isRepositoryStream = value.Stream is RepositoryStream || value.Stream is SenseNetSqlFileStream; var hasStream = isRepositoryStream || value.Stream is MemoryStream; if (!hasStream) { // do not do any database operation if the stream is not modified return; } FileStreamData fileStreamData = null; SqlProcedure cmd = null; try { string sql; CommandType commandType; if (blobProvider == BlobStorageBase.BuiltInProvider) { commandType = CommandType.StoredProcedure; sql = "proc_BinaryProperty_Update"; } else { commandType = CommandType.Text; sql = BlobStorage.FileStreamEnabled ? UpdateBinarypropertyNewFilerowFilestreamScript : UpdateBinarypropertyNewFilerowScript; } cmd = new SqlProcedure { CommandText = sql, CommandType = commandType }; cmd.Parameters.Add("@BinaryPropertyId", SqlDbType.Int).Value = value.Id; cmd.Parameters.Add("@ContentType", SqlDbType.NVarChar, 450).Value = value.ContentType; cmd.Parameters.Add("@FileNameWithoutExtension", SqlDbType.NVarChar, 450).Value = value.FileName.FileNameWithoutExtension == null ? DBNull.Value : (object)value.FileName.FileNameWithoutExtension; cmd.Parameters.Add("@Extension", SqlDbType.NVarChar, 50).Value = ValidateExtension(value.FileName.Extension); cmd.Parameters.Add("@Size", SqlDbType.BigInt).Value = value.Size; cmd.Parameters.Add("@Checksum", SqlDbType.VarChar, 200).Value = value.Checksum != null ? (object)value.Checksum : DBNull.Value; cmd.Parameters.Add("@BlobProvider", SqlDbType.NVarChar, 450).Value = value.BlobProviderName != null ? (object)value.BlobProviderName : DBNull.Value; cmd.Parameters.Add("@BlobProviderData", SqlDbType.NVarChar, int.MaxValue).Value = value.BlobProviderData != null ? (object)value.BlobProviderData : DBNull.Value; int fileId; if (BlobStorage.FileStreamEnabled) { string path; byte[] transactionContext; // Update row and retrieve file path and // transaction context for the Filestream column using (var reader = cmd.ExecuteReader()) { reader.Read(); fileId = reader.GetInt32(0); path = reader.GetSafeString(1); transactionContext = reader.IsDBNull(2) ? null : reader.GetSqlBytes(2).Buffer; } if (!string.IsNullOrEmpty(path)) { fileStreamData = new FileStreamData { Path = path, TransactionContext = transactionContext } } ; } else { fileId = (int)cmd.ExecuteScalar(); } if (fileId > 0 && fileId != value.FileId) { value.FileId = fileId; } } finally { cmd?.Dispose(); } // ReSharper disable once InvertIf if (blobProvider == BlobStorageBase.BuiltInProvider && !isRepositoryStream && streamLength > 0) { // Stream exists and is loaded -> write it var ctx = new BlobStorageContext(blobProvider, value.BlobProviderData) { VersionId = 0, PropertyTypeId = 0, FileId = value.FileId, Length = streamLength, UseFileStream = fileStreamData != null, BlobProviderData = new BuiltinBlobProviderData { FileStreamData = fileStreamData } }; BuiltInBlobProvider.UpdateStream(ctx, value.Stream); } }
/// <summary> /// Updates an existing binary property value in the database and the blob storage. /// </summary> /// <param name="blobProvider">Blob storage provider.</param> /// <param name="value">Binary data to update.</param> public void UpdateBinaryProperty(IBlobProvider blobProvider, BinaryDataValue value) { var streamLength = value.Stream?.Length ?? 0; if (blobProvider != BlobStorageBase.BuiltInProvider && streamLength > 0) { var ctx = new BlobStorageContext(blobProvider, value.BlobProviderData) { VersionId = 0, PropertyTypeId = 0, FileId = value.FileId, Length = streamLength, }; blobProvider.Allocate(ctx); using (var stream = blobProvider.GetStreamForWrite(ctx)) value.Stream?.CopyTo(stream); value.BlobProviderName = ctx.Provider.GetType().FullName; value.BlobProviderData = BlobStorageContext.SerializeBlobProviderData(ctx.BlobProviderData); } else { value.BlobProviderName = null; value.BlobProviderData = null; } if (blobProvider == BlobStorageBase.BuiltInProvider) { // MS-SQL does not support stream size over [Int32.MaxValue]. if (streamLength > int.MaxValue) { throw new NotSupportedException(); } } var isRepositoryStream = value.Stream is RepositoryStream; var hasStream = isRepositoryStream || value.Stream is MemoryStream; if (!hasStream) { // do not do any database operation if the stream is not modified return; } SqlProcedure cmd = null; try { string sql; CommandType commandType; if (blobProvider == BlobStorageBase.BuiltInProvider) { commandType = CommandType.StoredProcedure; sql = "proc_BinaryProperty_Update"; } else { commandType = CommandType.Text; sql = UpdateBinaryPropertyNewFilerowScript; } cmd = new SqlProcedure { CommandText = sql, CommandType = commandType }; cmd.Parameters.Add("@BinaryPropertyId", SqlDbType.Int).Value = value.Id; cmd.Parameters.Add("@ContentType", SqlDbType.NVarChar, 450).Value = value.ContentType; cmd.Parameters.Add("@FileNameWithoutExtension", SqlDbType.NVarChar, 450).Value = value.FileName.FileNameWithoutExtension == null ? DBNull.Value : (object)value.FileName.FileNameWithoutExtension; cmd.Parameters.Add("@Extension", SqlDbType.NVarChar, 50).Value = ValidateExtension(value.FileName.Extension); cmd.Parameters.Add("@Size", SqlDbType.BigInt).Value = value.Size; cmd.Parameters.Add("@Checksum", SqlDbType.VarChar, 200).Value = value.Checksum != null ? (object)value.Checksum : DBNull.Value; cmd.Parameters.Add("@BlobProvider", SqlDbType.NVarChar, 450).Value = value.BlobProviderName != null ? (object)value.BlobProviderName : DBNull.Value; cmd.Parameters.Add("@BlobProviderData", SqlDbType.NVarChar, int.MaxValue).Value = value.BlobProviderData != null ? (object)value.BlobProviderData : DBNull.Value; var fileId = (int)cmd.ExecuteScalar(); if (fileId > 0 && fileId != value.FileId) { value.FileId = fileId; } } finally { cmd.Dispose(); } // ReSharper disable once InvertIf if (blobProvider == BlobStorageBase.BuiltInProvider && !isRepositoryStream && streamLength > 0) { // Stream exists and is loaded -> write it var ctx = new BlobStorageContext(blobProvider, value.BlobProviderData) { VersionId = 0, PropertyTypeId = 0, FileId = value.FileId, Length = streamLength, BlobProviderData = new BuiltinBlobProviderData() }; BuiltInBlobProvider.UpdateStream(ctx, value.Stream); } }
protected internal override byte[] LoadBinaryFragment(int binaryPropertyId, long position, int count) { var commandText = @" SELECT SUBSTRING(Stream, @Position, @Count) FROM dbo.BinaryProperties WHERE BinaryPropertyId = @BinaryPropertyId "; byte[] result; using (var cmd = new SqlProcedure { CommandText = commandText }) { cmd.Parameters.Add("@BinaryPropertyId", SqlDbType.Int).Value = binaryPropertyId; cmd.Parameters.Add("@Position", SqlDbType.BigInt).Value = position + 1; cmd.Parameters.Add("@Count", SqlDbType.Int).Value = count; cmd.CommandType = CommandType.Text; result = (byte[])cmd.ExecuteScalar(); } return result; }
protected override bool NodeExistsInDatabase(string path) { var cmd = new SqlProcedure { CommandText = "SELECT COUNT(*) FROM Nodes WHERE Path = @Path", CommandType = CommandType.Text }; cmd.Parameters.Add("@Path", SqlDbType.NVarChar, PathMaxLength).Value = path; try { var count = (int)cmd.ExecuteScalar(); return count > 0; } finally { if (cmd != null) cmd.Dispose(); } }
public int InsertBinaryPropertyOld(int versionId, int propertyTypeId, BinaryDataValue value) { if (value.Stream != null && value.Stream.Length > Int32.MaxValue) throw new NotSupportedException(); // MS-SQL does not support stream size over [Int32.MaxValue] SqlProcedure cmd = null; //object pointer; int id = 0; try { cmd = new SqlProcedure { CommandText = "proc_BinaryProperty_Insert" }; cmd.Parameters.Add("@VersionId", SqlDbType.Int).Value = (versionId != 0) ? (object)versionId : DBNull.Value; cmd.Parameters.Add("@PropertyTypeId", SqlDbType.Int).Value = (propertyTypeId != 0) ? (object)propertyTypeId : DBNull.Value; cmd.Parameters.Add("@ContentType", SqlDbType.VarChar, 50).Value = value.ContentType; cmd.Parameters.Add("@FileNameWithoutExtension", SqlDbType.VarChar, 450).Value = value.FileName.FileNameWithoutExtension == null ? (object)DBNull.Value : (object)value.FileName.FileNameWithoutExtension; cmd.Parameters.Add("@Extension", SqlDbType.VarChar, 50).Value = ValidateExtension(value.FileName.Extension); cmd.Parameters.Add("@Size", SqlDbType.BigInt).Value = value.Size; cmd.Parameters.Add("@Checksum", SqlDbType.VarChar, 200).Value = (value.Checksum != null) ? (object)value.Checksum : DBNull.Value; ; //SqlParameter pointerParameter = cmd.Parameters.Add("@Pointer", SqlDbType.Binary, 16); //pointerParameter.Direction = ParameterDirection.Output; id = Convert.ToInt32(cmd.ExecuteScalar(), CultureInfo.CurrentCulture); //pointer = pointerParameter.Value; } finally { cmd.Dispose(); } if (value.Stream != null && value.Stream.Length > 0) { // Stream exists -> write it WriteBinaryStream(value.Stream, id); } return id; }