Hi

I have below code to save pdf file in sql. but getting error "Cannot Bulk Load. The File "D:\xyz.pdf" does not exist."

Private Sub ButBouncePdfAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButBouncePdfAdd.Click
        Try
            If TxtRefNo.Text <> "" Then
                OpenFileDialog1.InitialDirectory = "d:\"
                OpenFileDialog1.Title = "Select PDF File"

                OpenFileDialog1.Filter = "PDF Files|*.pdf"

                If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then



                    Dim FileName As String = OpenFileDialog1.FileName.ToString
                    Call Connect()
                    Dim cmd As New SqlClient.SqlCommand
                    cmd.Connection = CnCommon
                    cmd.CommandText = "UPDATE PDC_CHQ_IN_HAND SET PDF = (SELECT * FROM  OPENROWSET(BULK '" & FileName & "', SINGLE_BLOB) SOMEALIAS)  WHERE RefNo = '" & TxtRefNo.Text & "'"
                    cmd.ExecuteNonQuery()
                    MessageBox.Show("Image has been saved", "Save", MessageBoxButtons.OK)
                    CnCommon.Close()
                    CnCommon.Dispose()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

it exist on my local machine (Client). i am trying to save file in sql on server machine in office.

is there a way to update file from client machine.

Can a pdf file store in variable and use that variable to store in sql which can avoid file path.

You could try to reference the file as

\\machine\D$\file.pdf

This assumes that the server has access to your PC using the admin share. If not then you may need to set up a share (probably read only) to a folder set up strictly for that purpose.

Edited 1 Year Ago by Reverend Jim

This question has already been answered. Start a new discussion instead.