Can I use RBS in ASP.NET Applications?

May 30, 2013 at 11:49 AM
Edited May 30, 2013 at 2:30 PM
Hi,

I'm struggling to implement RBS on an ASP.NET application. If I do it as a Windows app it works.

Are there any special configurations that I have to consider?

Please help me on this.

Thanks and Regards,
Oshadha
Coordinator
May 31, 2013 at 7:44 AM
Hi,

It should work fine with ASP.NET application as well. Can you tell me more about the problems you are facing?

Thanks,
Vijendra.
Jun 9, 2013 at 5:39 AM
Edited Jun 9, 2013 at 2:55 PM
Hi Vijendra,

It gives me following error.

No provider of type <Filestream> found. Check the server configuration or install the provider on the client.

Following shows my code:
public void Create(string fullFileName, string connectionString, Attachment attachment)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromMinutes(10)))
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    SqlRemoteBlobContext blobContext = new SqlRemoteBlobContext(connection);

                    using (SqlRemoteBlob blob = blobContext.CreateNewBlob())
                    {
                        using (FileStream fileToRead = new FileStream(fullFileName, FileMode.Open))
                        {
                             blob.WriteFromStream(fileToRead);
                        }

                        scope.Complete();

                        using (SqlCommand cmd = new SqlCommand("InsertAttachment"))
                        {
                            cmd.Parameters.Add(new SqlParameter("@TableName", attachment.TableName));
                            cmd.Parameters.Add(new SqlParameter("@TableRowId", attachment.TableRowId));
                            cmd.Parameters.Add(new SqlParameter("@FileName", attachment.FileName));
                            cmd.Parameters.Add(new SqlParameter("@Extension", attachment.Extension));
                            cmd.Parameters.Add(new SqlParameter("@RowDescription", attachment.RowDescription));
                            cmd.Parameters.Add(new SqlParameter("@ModifiedDate", attachment.ModifiedDate));
                            cmd.Parameters.Add(new SqlParameter("@BlobId", blob.GetBlobId()));

                            cmd.Connection = connection;
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
            }
        }
This blob.WriteFromStream(fileToRead); is the place where I get above mentioned error.

Is there any Web.Config entries that I should place in?

Many Thanks,
Oshadha