1
我下面的其他post描述的存储和检索MSSQL 2008数据库的任何文件的方法时UnauthorizedAccessException。除了当我尝试将文件保存到磁盘上的任何位置时,一切运行良好,我得到UnauthorizedAccessException。以下是到目前为止已经完成VB.NET - 试图写一个文件来驱动
- 硬编码的路径事情“C:\ TEMP”和“d:\” -
- 尝试运行生成.exe作为管理员UnauthorizedAccessException - 程序意外关闭
任何人都可以点我在正确的方向来解决这个问题呢?
我在Windows 8上,下面是我使用的代码;
Public Sub downloadLearningObject(learningObjectID As Integer, folderPath As String) Implements ILearningObjectDAO.downloadLearningObject
Dim connection As String = DatabaseConnection.ConnectionString
Using con As New SqlConnection(connection)
con.Open()
Dim selectQuery As String = "SELECT File From LearningObject WHERE LearningObjectID=" & learningObjectID
Dim cmd As New SqlCommand(selectQuery, con)
Using sqlQueryResult = cmd.ExecuteReader()
If sqlQueryResult IsNot Nothing Then
sqlQueryResult.Read()
Dim blob = New [Byte]((sqlQueryResult.GetBytes(0, 0, Nothing, 0, Integer.MaxValue)) - 1) {}
sqlQueryResult.GetBytes(0, 0, blob, 0, blob.Length)
'the following line is producing the exception
Using fs = New FileStream(folderPath, FileMode.OpenOrCreate, FileAccess.ReadWrite)
fs.Write(blob, 0, blob.Length)
End Using
End If
End Using
End Using
End Sub