Cannot bulk load because the file could not be opened. Operating system error code 1326(Logon failure: unknown user name or bad password.)

不问归期 提交于 2019-12-10 10:54:56

问题


bulk upload from csv test file

"\servername\wwwroot\Upload\LDSAgentsMap.txt"

     SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[sp_CSVTest_BulkInsert] ( @Path NVARCHAR(128) )
AS 
    DECLARE @Sql NVARCHAR(256)
    SET @Sql = 'BULK
INSERT CSVTest 
FROM ''' + @Path + ''' WITH
(
FIELDTERMINATOR = '','',
ROWTERMINATOR = ''\n''
)'
--PRINT @Sql
EXEC(@Sql)

GO

path is "\servername\wwwroot\Upload\LDSAgentsMap.txt"

note

this is in shared hosting and database user have blukadmin and public service role


回答1:


This can occur when the Windows user account that SQL runs under (e.g. SqlServerAccount) doesn't have permissions to access the shared file (\servername\wwwroot\Upload\LDSAgentsMap.txt).

One way we've worked through this is to go to the machine where shared file resides. On that machine, add a Windows user account with the same user name and password as the account that SQL runs under.

For example,

If your database resides on MyDatabaseServer, and runs under a Windows user account SqlServerAccount with password Foo, then go to the machine where your shared file resides, e.g. MyFileServer, and create a Windows user account named SqlServerAccount with password Foo.

Last step: go into the folder share on MyFileServer and go into sharing properties for that folder. (On Win7, right-click the folder->Properties->Sharing->Advanced Sharing). Then add read permission for SqlServerAccount that you created.




回答2:


I was getting this error from SSIS when trying to execute a stored procedure which performed a bulk insert.

I fixed it by adding the SQL Server port number to the connection string in SSIS, forcing SSIS to access SQL Server through TCP/IP instead of Named Pipes.



来源:https://stackoverflow.com/questions/3785183/cannot-bulk-load-because-the-file-could-not-be-opened-operating-system-error-co

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!