3

I'm getting this exception:

An invalid parameter was passed to the function

when trying to create new instance from SqlFileStream. code:

var fileStream = new SqlFileStream(strSqlPath, bytArrContext, FileAccess.Write)

I checked for all the parameters non of them are null. I've been using this same exact code for awhile with no problems, i have no idea what's happening right now.

IBRA
  • 1,502
  • 3
  • 24
  • 56
  • What is `strSqlPath` and `bytArrContext` exactly? – Soner Gönül Apr 27 '14 at 14:41
  • @SonerGönül strSqlPath is the logical path for the file, and bytArrcontext is the transaction context byte array. – IBRA Apr 27 '14 at 14:58
  • 1
    @RASHOMON I think you missed some configuration on server, please check this link http://www.codeproject.com/Articles/128657/How-Do-I-Use-SQL-File-Stream – Reza Apr 27 '14 at 18:56
  • @RezaRahmati i already checked this article, didn't help :( but thanks for your reply – IBRA Apr 27 '14 at 19:01
  • @RASHOMON as another note, did you checked that the folder part of strSqlPath exists on ***Server***? – Reza Apr 27 '14 at 19:04
  • @RezaRahmati yes, all the values that were passed to the SqlFileStream were right, i think it's the issue is related to sql transaction or something, not sure, but am working on it. – IBRA Apr 27 '14 at 19:06
  • What operation? SELECT, INSERT, or UPDATE? – leppie Dec 08 '14 at 11:44
  • Do you have a solution? – Roel Feb 14 '19 at 15:49

2 Answers2

1

It is because of transaction. Please do this inside of a transaction scope.

Ayyappan
  • 26
  • 1
0

The current answer was not specific enough for me. The essence is that:

new SqlFileStream(dataRow["FileStreamPath"].ToString(), (byte[])dataRow["TransactionContext"], FileAccess.Read)

Should be called within the TransactionScope.

When you want to use the SqlFileStream you still have to be within the transaction. You can convert it to for example a regular MemoryStream to use it outside the transaction.

Roel
  • 3,089
  • 2
  • 30
  • 34