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

Does it exist on the database server?

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

I think bulk uploads look for files on the machine SQL is running on.

is there a way to update file from client machine.

Use an absolute network path?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.