Could Not Be Opened. Operating System Error Code 5
Contents |
SnehadeepOctober 29, 201013 0 0 0 While there are various forms of bulk copy this blog specifically deals with copying data from a file into SQL Server. It deals about the specific error “Operating
Cannot Bulk Load Because The File Could Not Be Opened. Operating System Error Code 5
system error code 5(Access is denied.)” which might crop up under certain circumstances when operating system error code 5 access is denied. sql server doing a bulk copy. For a while now I worked with a lot of DBAs and Developers bewildered with the problem
Operating System Error Code 5 Access Is Denied. . Bulk Insert
and most of them complaining about the lack of good documentation about it and hours spent diagnosing in the wrong direction. If you are looking for details about bulk copy visit http://msdn.microsoft.com/en-us/library/ms130809(SQL.90).aspx You operating system error code 5(access is denied.) sql server 2008 run the following query BEGIN BULK INSERT ENVPOT_R FROM ‘\\advdev64\BulkTest\test_bulk_insert.txt' WITH ( FIELDTERMINATOR = ‘;', ROWTERMINATOR = ‘\n') END And end up getting the following error Msg 4861, Level 16, State 1, Line 1 Cannot bulk load because the file operating system error code 5(access is denied.) sql server 2012 "\\advdev64\BulkTest\test_bulk_insert.txt" could not be opened. Operating system error code 5(Access is denied.). The usual troubleshooting that DBAs do is to chase the “Access Denied” error from a file/folder access perspective. Some of them are as follows. a) Added “full” access to “everyone” (just temporary to test this) on the BulkTest folder and still getting the same error. b) Added “full” access to the SQL server service account on the BulkTest folder and still get the same error. c) The user is made a member of the bulkadmin fixed server role. Many DBAs come with prior experience on SQL Server 2000 where the following was true. Once a user was authenticated, access to external files was based on the security profile of the SQL Server process. When the SQL Server process had read access to a file, for a user that did not have access to the file but was a member of the bulkadmin fixed server role, the user could import the file by using BULK INSERT and access the contents of the file. But that had a security issue
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings
Operating System Error Code 3
and policies of this site About Us Learn more about Stack operating system error code 3 the system cannot find the path specified Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
Operating System Error Code 5(failed To Retrieve Text For This Error. Reason: 15105)
Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; https://blogs.msdn.microsoft.com/dataaccesstechnologies/2010/10/29/sql-bulk-copy-error-operating-system-error-code-5access-is-denied/ it only takes a minute: Sign up Cannot bulk load. Operating system error code 5 (Access is denied.) up vote 11 down vote favorite 3 For some weird reason I'm having problems executing a bulk insert. BULK INSERT customer_stg FROM 'C:\Users\Michael\workspace\pydb\data\andrew.out.txt' WITH ( FIRSTROW=0, FIELDTERMINATOR='\t', ROWTERMINATOR='\n' ) I'm confident after reading this that I've setup my user role correctly, as http://stackoverflow.com/questions/14555262/cannot-bulk-load-operating-system-error-code-5-access-is-denied it states... Members of the bulkadmin fixed server role can run the BULK INSERT statement. I have set the Login Properties for the Windows Authentication correctly (as seen below).. to grant server-wide permissions on bulkadmin And the command EXEC sp_helpsrvrolemember 'bulkadmin' tells me that the information above was successful, and the current user Michael-PC\Michael has bulkadmin permissions. But even though I've set everything up correctly as far as I know, I'm still getting the error. executing the bulk insert directly from SQL Server Management Studio. Msg 4861, Level 16, State 1, Line 2 Cannot bulk load because the file "C:\Users\Michael\workspace\pydb\data\andrew.out.txt" could not be opened. Operating system error code 5(Access is denied.). which doesn't make sense because apparently bulkadmins can run the statement, am I meant to reconfigure how the bulkadmin works? (I'm so lost). Any ideas on how to fix it? sql-server tsql bulkinsert share|improve this question edited Jan 28 '13 at 7:56 asked Jan 28 '13 at 4:02 Killrawr 2,45322358 Sounds like the problem is external to SQL Server. Can you open the file
log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company http://dba.stackexchange.com/questions/44524/bulk-insert-through-network Business Learn more about hiring developers or posting ads with us Database Administrators Questions Tags Users Badges Unanswered Ask Question _ Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve http://blog.arjanfraaij.com/2010/12/bulk-admin-operating-system-error-code.html their database skills and learn from others in the community. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up operating system and rise to the top Bulk Insert Through Network up vote 7 down vote favorite 3 Can someone help me with these? BULK INSERT DATABESE01.dbo.TABLE01 FROM '\\COMPUTER01\FOLDER01\TextFile.txt' WITH ( FIELDTERMINATOR = ' ', rowterminator = '\n', tablock ) The error shows, couldn't open: Could not bulk insert because file '\SERVERNAME\FOLDERNAME\textFile.txt' could not be opened. Operating system error code 5(Access is denied.) The path is on another computer on the network. sql-server bulk-insert share|improve this question operating system error edited Dec 3 '14 at 6:02 RolandoMySQLDBA 107k15138274 asked Jun 13 '13 at 8:18 Imperial Jonas 38114 migrated from stackoverflow.com Jun 14 '13 at 11:20 This question came from our site for professional and enthusiast programmers. 7 Does the account that SQL Server is running under have permission to access '\\COMPUTER01\FOLDER01\TextFile.txt'? Note that the account will generally be different from your account. –Damien_The_Unbeliever Jun 13 '13 at 8:55 3 Can you also add the exact error you get? –ypercubeᵀᴹ Jun 14 '13 at 11:22 in addition to @Damien_The_Unbeliever: "To specify a shared data file, use its universal naming convention (UNC) name, which takes the general form, \\Servername\Sharename\Path\Filename" –JoseTeixeira Jun 14 '13 at 11:52 @ypercube - Could not bulk insert because file '\\SERVERNAME\FOLDERNAME\textFile.txt' could not be opened. Operating system error code 5(Access is denied.). thank you sir –Imperial Jonas Jun 15 '13 at 2:43 I have the same issue using the same domain and cross domain (Operating system error code 5(Access is denied.)). Interestingly, if I use XP_CMDSHELL to test if the file exists or i can even move the file, but the bulk insert throws access denied. The sql service account and my windows account both have permissions to the folder. –user53311 Dec 3 '14 at 2:00 | show 1 more comment 3 Answers 3 act
SQL01\Acceptance and SQL01\Production The customer wanted to use BULKINSERTS and was granted Server Role BULKADMIN on all instances. The below SQL Statement was executed on the SQL01\Test Instance. The result was as expected, data was inserted in tblSomeTable. Then they tried to execute the same statement on the SQL01\Acceptance and Production instance what resulted in the error:msg 4861, Level 16, State 1, Line 1Cannot bulk load because the file "\\SomeShare\SomeFolder\SomeFile.txt" could not be opened. Operating system error code 5(Access is denied). The first thing I checked has the user all needed permissions on the share, it was working on Test using the same SQL Active Directory based principal and share so that could not be the issue. The second check if principal has the bulkadmin server role granted on all instances: I hope you trust me when I say that this is correctly granted on all instances. So I needed to go a bit deeper. To understand what was needed first I need to show you a little image of how the environment is working: On the client they started SSMS 2008, and executed the given BULK INSERT command. The image explains that there are 2 hops or so cold "Double Hop" needed to get to the files. This means that the SQL01 instances need to be able to forward the user security token to the FILE1 server file share. This requires KERBEROS authentication and delegation! So the first thing I checked was what protocol is used for each connection. This resulted in:- SQL01\Test TCP KERBEROS- SQL01\Acceptance TCP NTLM- SQL01\Production TCP NTLM So there is the reason why it is not working, NLM does not support the authentication pass through. But what is causing this? You can not configure this as a setting direct in SQL Server. Lucky I have some experience with Kerberos configuring for SharePoint environments. The next thing I did was looking for the SPN (Server Principal Names) that are created for the SQL Server Service accounts for each Instance. SPN's needed to be configured for each Service Account to make sure Kerberos delegation is supported. You need the Windows resource kit to be able to check SPN's with the setspn tool. I executed setspn -L