Bulk load permissions - sql-server

I have server rrp-graph with installed SQL Server 2008 R2 instance which runs from Local System account.
I have another server rrp-garchive with shared folder. I'm sorry for russian language, it says that I granted full access to folder to rrp-graph computer.
Ok, now I want to BULK insert a file from shared folder (on server rrp-garchive) to table on server rrp-graph. I do:
INSERT INTO dbo.tREL_IUAttributes4IULog_BLOB WITH (TABLOCK) (IULog_ID, AttributeIULog_ID, Value, OrderPos)
SELECT 1, 30, rs.BulkColumn, 1 FROM
OPENROWSET(BULK N'\\rrp-garchive\KSPDImagesBaseTest\12\15\00\12150014.tif', SINGLE_BLOB) rs
But I receive following error:
Cannot bulk load because the file "\\rrp-garchive\KSPDImagesBaseTest\12\15\00\12150014.tif" could not be opened. Operating system error code 5(failed to retrieve text for this error. Reason: 15105).
What else should I do to be able to do bulk operations. Thanks.

Related

Filestream and using bulk insert via OPENROWSET gives File could not be opened. Operating system error code 50(The request is not supported.)

I felt in love with the filestream capacities of SQL Server giving the possibility to see only files and skip the complexity of hierarchies.
When I import a xml file in a table using openrowset I get this error:
INSERT INTO tblXmlFiles(IdTache, idSuiviTrt, XMLFileName, XMLData)
SELECT 0, 0, '\OMEGA\XMLFiles\XMLFiles\XMLFiles\Test1.xml', CONVERT(XML, BulkColumn)
FROM OPENROWSET(BULK '\OMEGA\XMLFiles\XMLFiles\XMLFiles\Test1.xml', SINGLE_BLOB) AS x;
Msg 4861, Level 16, State 1, Line 16
Cannot bulk load because the file "\OMEGA\XMLFiles\XMLFiles\XMLFiles\Test1.xml" could not be opened. Operating system error code 50(The request is not supported.).
Completion time: 2023-01-26T13:48:40.3212373+01:00
It kind of spoils all the fun because both functionalities are incorporated into SQL Server but apparently the SQL Server team does not let them work together.
On the web I found that the issue might be related to rights but it is impossible to give rights to an filestream network drive. The tab is missing.
Can anyone help me out, please?
I tried to import the same file on a local disk and there it works seamlessly. I tested it on 2019 and 2022. Same result. Also Windows 2019/2022.
Sounds like permissions issue indeed. You need to check that the account your MSSQL instance is running under has all necessary permissions on the shared folder (XMLFiles on OMEGA). For that (provided it's Windows) go to the server, open Properties of the folder and then Sharing and Security tabs. Also is your network path correct (server name prefixed with '\' vs '\\' and 'XMLFiles' repeated 3 times)?

SQL Server OPENROWSET without SYSADMIN role

We extensively use the OPENROWSET function to import .CSV and Excel files into our SQL Server 2012 environment, using MSDASQL or ACE:
SELECT *
FROM OPENROWSET ('MSDASQL',
'DRIVER={MICROSOFT access TEXT DRIVER (*.TXT, *.CSV)};',
'SELECT * FROM E:\INCOMING\REPORT_EXTRACT.CSV')
Or using ACE:
SELECT * FROM OPENROWSET('MICROSOFT.ACE.OLEDB.12.0','TEXT;DATABASE=E:\INCOMING\;HDR=YES;', 'SELECT * FROM [REPORT_EXTRACT.CSV]');
We're experiencing the classic error message:
Msg 7415, Level 16, State 1, Line 1
Ad hoc access to OLE DB provider 'MSDASQL' has been denied. You must access this provider through a linked server.
The ONLY workaround to enable this, is granting said user(s) with the SYSADMIN role - obviously not ideal.
The location of the file(s) is on the server itself, for which the users accessing DO have the necessary permissions to access that file folder. The SQL Server service is running under the local system account with permission to interact with the desktop.
We've tried the following workarounds/fixes to no avail:
1 Executed the following code:
EXEC master . dbo. sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′ , N’AllowInProcess’ , 1
GO
EXEC master . dbo. sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′ , N’DynamicParameters’ , 1
GO
*2 The DisAllowAdHocAccess registry fix:
This is the current state:
3 Adding the ADMINISTER BULK OPERATIONS permission to the said users
We have dozens of expressions and files within our procedures that use OPENROWSET, therefore BULK INSERT, building SSIS packages, leverage Excel files as linked servers are NOT feasible options.
Any suggestions?
Wow - After YEARS of troubleshooting, I finally figured out what it was!
The registry entry value that controls the Allowing of Ad-hoc access, relies on the DisallowAdHocAccess being in that EXACT sentence case.
In our case, the "A" in AdHoc was not capitalized:
To fix this, I:
Deleted the registry value as described
Re-enabled the Disallow AdHoc Access option (Which re-created the registry value)
Manually set the Registry DisallowAdHocAccess value to "0"
Problem solved!

Unable to load xml file in Sqlserver:Cannot bulk load because the file could not be opened. Operating system error code (null)

I need to load data from xml file in to sql server table column.Tried the below query
declare #fileData nvarchar(max)
Select #fileData=BulkColumn
from OpenRowSet(Bulk 'C:\Testfile\Test.xml', Single_blob ) x;
But I am getting the below error
Cannot bulk load because the file "C:Testfile\Test.xml" could not be opened. Operating system error code (null).
Am trying from SSMS in my machine,i dont have access to sql server machine.

BULK INSERT returns error "Access is denied"

When running Bulk Insert
BULK INSERT MyDatabase.dbo.MyTable
FROM '\\Mylaptop\UniversalShare\SQLRuleOutput.csv'
WITH (FIRSTROW = 2, FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')
on a remote SQL Server I get this error:
"Cannot bulk load because the file
"\MyLaptop\UniversalShare\SQLRuleOutput.csv" could not be opened.
Operating system error code 5(Access is denied.)."
The share is open to all.
I have run PowerShell Invoke-SQLCMD scripts on that SQL Server that where it connects to that same share, so the server can see the share.
This Bulk Insert statement fails with the same error whether I run it directly as T-SQL on the SQL Server, or through PowerShell Invoke-SQLCMD (which is my intended method).
This question is similar, Cannot bulk load. Operating system error code 5 (Access is denied.), but in my case the share is open to all, so permissions shouldn't be an issue, and the share is definitely in a different place (my laptop for POC development) than SQL Server.
Does anyone know why this error is happening, or how to get around it?
Thanks,
Conrad
The share must be accessible to the Windows account that the MSSQL Service is running under; typically Local System or Network Service (but could be anything). Its unlikely you have explcitly granted access to MYSERVER\LOCAL SERVICE to your local file share.
Running Powershell Invoke-SQLCMD doesn't demonstrate that the MSSQL service has rights to your drive - it depends what account you are running power shell as.

Creating a linked server from SQL Server X64 to text and Excel using the Access driver

We are now in progress of moving all our production databases from a SQL Server 2005 32 bit instance to a brand new SQL Server 2012 64 bit instance.
one of the main hardships that our developers still suffer is Linked Servers.
We have a lot of programs that need to get some data from text, csv or excel files, and the way it's implemented is with a linked server to text files so you can easily throw a select statement to the text file and insert it into a table.
The problem raised that the 32 bit server used the Microsoft.Jet.OLEDB.4.0 driver the files where on a sheared directory that had full permissions for everyone and we never ran into security issues.
On the new 64 bit server we added a linked server with the following syntax:
USE [master]
GO
EXEC master.dbo.sp_addlinkedserver
#server = N'TEMP_FILES_1'
, #srvproduct=N''
, #provider=N'Microsoft.ACE.OLEDB.12.0'
, #datasrc=N'\\SERVER-APP01\BWA\TempFiles'
, #provstr=N'Text'
Note:
The data source is on a network share.
The MSSQL service runs as the domain administrator account.
I'm logged in remotely as the domain administrator which is of course a local administrator too.
The \\SERVER-APP01\BWA\TempFiles directory has full access set for everyone.
Now when i run EXEC sp_testlinkedserver [TEMP_FILES_1] i get the following error message:
OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "TEMP_FILES_1" returned message "'\\SERVER-APP01\BWA\TempFiles' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.".
This is definitely a security issue, but the funny part is that when i run xp_cmdshell 'dir \\SERVER-APP01\BWA\TempFiles' it returns records so obviously the service has access to this folder...
On the other side on my local computer i also have a 64 bit instance with the same linked server and it works like a charm!
I've been crawling around the internet to find a solution to my problem but seems that linked servers to text files is used very little especially with 64 bit.
We had to copy the file to a drive on the destination SQL Server system before we could read the data as below:
EXEC xp_cmdshell 'net use y: \\[source directory path] [pw] /USER:[active user]'
EXEC xp_cmdshell 'copy y:\[source file] [destination directory]'
EXEC xp_cmdshell 'net use y: /delete'

Resources