1
Vote

Error: Invalid handle.\r\nParameter name: handle

description

Error Message is : "Invalid handle.\r\nParameter name: handle" on line :
 
The code instruction generating the error is : FileStream destBlob = new FileStream(handle, FileAccess.Write);
 
Stack Trace is :
 
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>FileStreamLoader.vshost.exe</AppDomain><Exception><ExceptionType>System.ArgumentException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Invalid handle.
Parameter name: handle</Message><StackTrace> at System.IO.FileStream..ctor(SafeFileHandle handle, FileAccess access, Int32 bufferSize, Boolean isAsync)
at System.IO.FileStream..ctor(SafeFileHandle handle, FileAccess access)
at FilestreamLoader.Program.Main() in C:\demos\Katmai\SQLSrvE2E_SQL2K8_Samples_v1.1\SQLSrvE2E_SQL2K8_Samples_v1.1\FILESTREAM-WPF-HTTP Sample\CS\FilestreamWpfHttp\FilestreamLoader\main.cs:line 106
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()</StackTrace><ExceptionString>System.ArgumentException: Invalid handle.
Parameter name: handle
at System.IO.FileStream..ctor(SafeFileHandle handle, FileAccess access, Int32 bufferSize, Boolean isAsync)
at System.IO.FileStream..ctor(SafeFileHandle handle, FileAccess access)
at FilestreamLoader.Program.Main() in C:\demos\Katmai\SQLSrvE2E_SQL2K8_Samples_v1.1\SQLSrvE2E_SQL2K8_Samples_v1.1\FILESTREAM-WPF-HTTP Sample\CS\FilestreamWpfHttp\FilestreamLoader\main.cs:line 106
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()</ExceptionString></Exception></TraceRecord>
 
 
Connection to the database are ok, I have traced with SQL Profiler :
 
exec sp_executesql N'INSERT [dbo].[media]([mediaId], [fileName], [contentType]) VALUES( @mediaId, @fileName, @contentType);',N'@mediaId uniqueidentifier,@fileName nvarchar(256),@contentType nvarchar(256)',@mediaId='1AB1E4B3-1F87-48DF-B3FA-88582E3D29D4',@fileName=N'RogAndZachOnFilestream.wmv',@contentType=N'video/x-ms-wmv'   exec sp_executesql N'SELECT [file].PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT() FROM [dbo].[media] WHERE [mediaId] = @mediaId;',N'@mediaId uniqueidentifier',@mediaId='1AB1E4B3-1F87-48DF-B3FA-88582E3D29D4'

comments

ZachSkylesOwens wrote Nov 21, 2007 at 9:34 PM

This issue was found by a developer in France.

After going back and forth a few times we discovered that the problem was he was using SQL Server authentication mode and using "sa". We developed these samples using Windows Authentication. Once he updated his configuration the sample ran without an issue.

We will investigate what changes need to be made for SQL Server authentication mode to work properly before closing this Issue.

wrote Nov 21, 2007 at 9:34 PM

wrote Nov 21, 2007 at 9:37 PM

wrote Nov 22, 2007 at 4:32 AM

I reproduced this and forwarded to FILESTREAM team for investigation.  Great catch!

rfyffe wrote Apr 3, 2012 at 10:30 AM

I too am having this problem. The only diffence is that i'm already using windows authentication to connect to my DB. I'm using Visual Studio 2005 and MSSQL 2008.
This is and example of my connection string
<add key="ServerConnStr" value="Data Source=SYSLT1990;Initial Catalog=TEST_DB;Integrated Security=SSPI"/>

Please tell me wat to do here i'm deperate. Thanks

wrote Feb 13, 2013 at 11:57 PM