SqlException was unhadled: Cannot bulk load Error

I have an error when executing SQL Stored Procedure 2008 R2 using VB.net 2010

Errors:
SqlException was unhandled:
Cannot bulk load because the file could not be opened. Operating System error code 5(Access is denied).

VB.net 2010 code:
Dim sqlConnection1 As New SqlConnection("Data Source=Main;Initial Catalog=Main;Persist Security Info=True;User ID=sa;Password=hello")
        Dim cmd As New SqlCommand
        Dim rowsAffected As Integer

        cmd.CommandText = "spImportBulkInsertCommand"
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Connection = sqlConnection1

        sqlConnection1.Open()

        rowsAffected = cmd.ExecuteNonQuery()

        sqlConnection1.Close()

Open in new window



SQL Server 2008 R2 Stored Procedure:
ALTER PROCEDURE [dbo].[spImportBulkInsertCommand]
	
AS
BEGIN
 BULK INSERT  [dbo].[tblImportBulk]
FROM '\\network\InsertBulk.txt'

WITH
(
 FIELDTERMINATOR = ',',
 ROWTERMINATOR = '\n' 
) 

Open in new window



Thank you for your help.
Queennie LAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Deepak ChauhanSQL Server DBACommented:
You are using SQL authentication to access network share and i guess SQL service account is localsystem.

This account does not have access on the network share.

add <sqlserverComputerName> to Networkshare property and grant appropriate permission at least read permission.
Queennie LAuthor Commented:
@deepakChauhan:

How to do that?

Thank you.
Deepak ChauhanSQL Server DBACommented:
Connect the server where Network share folder exists and right click on the folder>
click on security tab> add > click on objects type> check mark Computers> type the SQL server computername > click on check names

now you can see the <computername>$  add this and assign the permissions.
Or

execute above code using windows authentication account and add this account in the security of network share folder same as above.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Queennie LAuthor Commented:
I did add the sql server computer name but it still giving me the same error.
Deepak ChauhanSQL Server DBACommented:
Are you able to execute this procedure in ssms? Share the error no. as well.

In addition try to execute this command, this way you can make sure you have permissions to connect the shared directory.

Xp_cmdshell 'dir \\networkshare\'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Deepak ChauhanSQL Server DBACommented:
Did you check the above.
Queennie LAuthor Commented:
Thank you deepakChauhan.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.