I am trying to bulk insert a file from remote server to MS SQL server.
CONN = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("ReadEMAPI.My.MySettings.IntradayDataConn").ConnectionString)
cmd.Connection = CONN
CONN.Open()
cmd.CommandText = "BULK INSERT BidAsk FROM '" & "G:\Intraday Data\EMAPI\SET\Test.csv" & "' WITH (FIELDTERMINATOR=',', ROWTERMINATOR='\n',KEEPNULLS)"
cmd.ExecuteNonQuery()
CONN.Close()
I got this error:
Cannot bulk load because the file ""G:\Intraday Data\EMAPI\SET\Test.csv"" could not be opened. Operating system error code 3(The system cannot find the path specified.).
However, when I ran the sql command exactly the same in MSSQL Management Studio on the server, it was able to execute correctly.
Please help.
G:is a network path, it's generally better to use UNC paths. Also ensure SQL Server Service account has access to the directory.BULK INSERThappens in the context of your own Domain or Windows account. If the VB program uses different Domain or Windows credentials then theBULK INSERThappens in the context of that Domain or Windows account. If the VB program uses SQL Login credentials then theBULK INSERThappens in the context of the Domain or Windows account under which the SQL Server service is running.BULK INSERTwith a SQL Authentication Login. TheLOGINsimply needs permission to perform Bulk Operations.