Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 530619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:12:57+00:00 2026-05-13T09:12:57+00:00

Dear Folk’s i’m using the following code in order to send the bytes of

  • 0

Dear Folk’s i’m using the following code in order to send the bytes of a picture into the stream table:

Dim FirstColumnNames As String = imTable(0) & "_Code, " & imTable(0) & "_Price, " & imTable(0) & "_Title, " & imTable(0) & "_Type, " & imTable(0) & "_Height, " & imTable(0) & "_Width, " & imTable(0) & "_Comments "
Dim FirstFieldsValues As String = "'" & imParam(1) & "', '" & imParam(2) & "', '" & imParam(0) & "', '" & imType.ToString & "', '" & imHeight & "', '" & imWidth & "', '" & imParam(3) & "' "
RemoteSQLcmd = New SqlCommand("INSERT INTO " & imTable(0) & " (" & FirstColumnNames & ")  VALUES (" & FirstFieldsValues & ") ", RemoteSQLConn, RemoteSQLtx)
RemoteSQLcmd.ExecuteNonQuery()
RemoteSQLcmd = New SqlCommand("SELECT * FROM " & imTable(0) & " WHERE " & imTable(0) & "_Code = " & "'" & imParam(1) & "'", RemoteSQLConn, RemoteSQLtx)
AbsRecord = RemoteSQLcmd.ExecuteScalar
Dim imGUID As Guid = Guid.NewGuid()
Dim SecondColumnNames As String = imTable(1) & "_" & imTable(0) & "_ID , " & imTable(1) & "_GUID "
Dim SecondFieldsValues As String = "'" & AbsRecord & "', '" & imGUID.ToString & "'"
RemoteSQLcmd = New SqlCommand("INSERT INTO " & imTable(1) & " (" & SecondColumnNames & ")  VALUES (" & SecondFieldsValues & ") ", RemoteSQLConn, RemoteSQLtx)
RemoteSQLcmd.ExecuteNonQuery()
RemoteSQLcmd = New SqlCommand("SELECT GET_FILESTREAM_TRANSACTION_CONTEXT() " & "FROM " & imTable(1) & " WHERE " & imTable(1) & "_" & imTable(0) & "_ID = " &AbsRecord, RemoteSQLConn, RemoteSQLtx)
RemoteSQLcmd.Parameters.Add("@" & imTable(1) & "_GUID", SqlDbType.UniqueIdentifier).Value = imGUID
Dim tokenObject As Object = RemoteSQLcmd.ExecuteScalar()
tokenReader = RemoteSQLcmd.ExecuteReader(CommandBehavior.SingleRow)
tokenReader.Read()
filePathName = tokenReader.GetSqlString(1)
fileToken = DirectCast(tokenReader(3), Byte())
tokenReader.Close()
Dim sqlFile As SqlFileStream = New SqlFileStream(filePathName.Value, fileToken.Value, FileAccess.Write)

The tables have the fllowing stracture
Thats the First Table:

myCommand = New SqlCommand("CREATE TABLE " & TablesStat(0, 0) & _
                    " (" & TablesStat(0, 0) & "_ID int NOT NULL PRIMARY KEY IDENTITY(1,1), " & TablesStat(0, 0) & "_Code varchar(20) NULL, " & TablesStat(0, 0) & "_Price money NULL, " & TablesStat(0, 0) & "_Title varchar(50) NULL, " & TablesStat(0, 0) & "_Type sql_variant NULL, " & TablesStat(0, 0) & "_Height int NULL, " & TablesStat(0, 0) & "_Width int NULL, " & TablesStat(0, 0) & "_Comments nvarchar(MAX) NULL)", RemoteSQLConn)
myCommand.ExecuteNonQuery()

End the second table is:

myCommand = New SqlCommand("CREATE TABLE " & TablesStat(1, 0) & _
   " (" & TablesStat(1, 0) & "_ID int NOT NULL PRIMARY KEY IDENTITY(1,1), " & TablesStat(1, 0) & "_GUID UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUE , " & TablesStat(1, 0) & "_" & TablesStat(0, 0) & "_ID int FOREIGN KEY REFERENCES " & TablesStat(0, 0) & " (" & TablesStat(0, 0) & "_ID) NOT NULL, " & TablesStat(1, 0) & "_Image varbinary(MAX) FILESTREAM NULL ) ", RemoteSQLConn)

myCommand.ExecuteNonQuery()

My problem comes when i’m trying to read the ‘filePathName’ and the ‘fileToken’
the privious SELECT GET_FILESTREAM…. return me only one colomn to read the colomn 0 which has the GUID in binary format
I know i’m doing something wrong but i don’t know what

My issue is that i’m not geting th ‘filePathName’ and the fileToken’

is there anybody to assist me?


Look Max

I did what you told me but nothing

RemoteSQLcmd = New SqlCommand("SELECT GET_FILESTREAM_TRANSACTION_CONTEXT()", RemoteSQLConn, RemoteSQLtx) 
Dim tokenObject As Object = RemoteSQLcmd.ExecuteScalar() 
tokenReader = RemoteSQLcmd.ExecuteReader(CommandBehavior.SingleRow) 
tokenReader.Read() 
fileToken = DirectCast(tokenReader(1), Byte()) 
filePathName = tokenReader.GetSqlString(3)

And the Transaction starts far upper of this command

And never stops


Dim imGUID As Guid = Guid.NewGuid()
Dim imImage As Byte() = New Byte(imStream.Length) {}
Dim bytesRead As Integer = imStream.Read(imImage, 0, imStream.Length)
Dim SecondColumnNames As String = _
            imTable(1) & "_GUID, " & _
            imTable(1) & "_" & imTable(0) & "_ID"
Dim SecondFieldsValues As String = "'" & imGUID.ToString & "', '" & AbsRecord & "'"
RemoteSQLcmd = New SqlCommand("INSERT INTO " & imTable(1) & _
            " (" & SecondColumnNames & ")  VALUES (" & SecondFieldsValues & ")", RemoteSQLConn, RemoteSQLtx)
RemoteSQLcmd.Parameters.Add("@" & imTable(1) & "_GUID", SqlDbType.UniqueIdentifier).Value = imGUID
  RemoteSQLcmd.Parameters.Add("@" & imTable(1) & "_Image", SqlDbType.Image).Value = imImage
  RemoteSQLcmd.ExecuteNonQuery()
  RemoteSQLcmd = New SqlCommand("SELECT GET_FILESTREAM_TRANSACTION_CONTEXT() FROM " & imTable(1), RemoteSQLConn, RemoteSQLtx)
Dim tokenObject As Object = RemoteSQLcmd.ExecuteScalar()
tokenReader = RemoteSQLcmd.ExecuteReader(CommandBehavior.SingleRow)
tokenReader.Read()

As you can see i put again the FROM claus.

But please look what i’m receiving in the reader


tokenReader.Depth 0

tokenReader.FieldCount 1

tokenReader.HasRows True

tokenReader.IsClosed False

tokenReader.Item In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user.

tokenReader.RecordsAffected -1


As you can see here i have only one column to read and nothing else

I really don’t know if that is helpful but anyway i put it there

tokenReader.VisibleFieldCount 1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:12:57+00:00Added an answer on May 13, 2026 at 9:12 am

    MSDN said you should

    • do this inside TRANSACTION
    • do “SELECT GET_FILESTREAM_TRANSACTION_CONTEXT()” without any “FROM TABLE”

    There is a sample in Working with FILESTREAM using VB .NET By Yan Pan:

    ' Obtain a transaction context. All FILESTREAM BLOB operations occur '
    ' within a transaction context to maintain data consistency. '
    Dim transaction As SqlTransaction = 
        sqlConnection.BeginTransaction("mainTranaction")
    sqlCommand.Transaction = transaction
    sqlCommand.CommandText = "SELECT GET_FILESTREAM_TRANSACTION_CONTEXT()"
    Dim obj As Object = sqlCommand.ExecuteScalar()
    Dim txContext As Byte() = Nothing
    If Not obj.Equals(DBNull.Value) Then
        txContext = DirectCast(obj, Byte())
    Else
        Throw New System.Exception("GET_FILESTREAM_TRANSACTION_CONTEXT() failed")
    End If
    
    ' Obtain a handle that can be passed to the Win32 FILE APIs. '
    Dim sqlFileStream As New SqlFileStream(filePath, txContext, FileAccess.Write)
    
    ' Converting the image to a byte array. '
    ' Please change C:\Spire.jpg to your image file path. '
    Dim byteImg As Byte()
    byteImg = File.ReadAllBytes("C:\Spire.jpg")
    'Write the image file to the FILESTREAM BLOB. '
    sqlFileStream.Write(byteImg, 0, byteImg.Length)
    
    ' Close the FILESTREAM handle. '
    sqlFileStream.Close()
    
    ' Commit the write operation that was performed on the FILESTREAM BLOB. ' 
    sqlCommand.Transaction.Commit()
    

    Try to change your code according to sample:

    • filePath variable is initiated before opening file transaction
    • there is a simple “SELECT GET_FILESTREAM_TRANSACTION_CONTEXT()” command for file context
    • there is a null check and DirectCast(obj, Byte()) to cast value into byte
    • not sure if it make difference, but SqlFileStream is opening with txContext, not txContext.Value

    UPDATE
    How I understand the problem:

    filePathName – filename from where we will open filestream. this value should be selected from some field of some your table. If you don’t know what [table].[field] it is, see inside db table values and find where file path are saved.

    fileToken – filestream transaction context. should be selected in separate command execute, and casted to Byte.


    SQL Injections means when you do things like

    RemoteSQLcmd = New SqlCommand("SELECT * FROM " & imTable(0) & " WHERE " 
        & imTable(0) & "_Code = " & "'" & imParam(1) 
        & "'", RemoteSQLConn, RemoteSQLtx)
    

    in codebehind and imParam is an URL parameter value than someone may play a bad joke with you putting “‘; DROP TABLE users;” in it which may resolve into

    SELECT * FROM table WHERE table_Code = ''; DROP TABLE users;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 299k
  • Answers 299k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have a look at Mindscape's WPF Star Diagrams or WPF… May 13, 2026 at 7:50 pm
  • Editorial Team
    Editorial Team added an answer Multithreaded programming is parallel, but parallel programming is not necessarily… May 13, 2026 at 7:50 pm
  • Editorial Team
    Editorial Team added an answer You need to create a reporting repository schema like this:… May 13, 2026 at 7:50 pm

Related Questions

Dear Stacktoverflow, can you show me an example of how to use a QScrollBar?
Dear g++ hackers, I have the following question. When some data of an object
Dear all, I am writing a python program that is retrieving edifact log messages
Dear all, I save formatted text (bold, changed in font, style...etc) in an nvarchar(max)
Dear all, I have a question about Facebook Page: ( NOT user profile page,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.