Adding image to SQL server without bulk load permissions - sql-server

I'm trying to upload an image to our SQL server via a web form, but am getting this error when I try to run the script:
Msg 4834, Level 16, State 1.
You do not have permission to use the bulk load statement.
The web form uploads the image to our server, before running the below script and then deleting the image file from the server
UPDATE ourTable
SET NewImage = (SELECT * FROM OPENROWSET(BULK N'https://our-server.com/just-and-image.jpg', SINGLE_BLOB) as img)
WHERE ID = 01
For various reasons we have to store the image in the DB rather than in a directory and we can't change the SQL perms.
Is there another, better way to do this?

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 Bulk Import error when running inside docker container on Windows

I am running the SQL Server for Linux container (mcr.microsoft.com/mssql/server) on Docker for Windows. I keep getting an error when I try to do a Bulk Import or OpenRowSet of data stored in an Azure Blob using the Azure Data Studio for Windows.
Command:
BULK INSERT dbo.MY_TABLE
FROM 'data/aaa/bbb/xxxxxxx.CSV'
WITH (
DATA_SOURCE = 'SxxxxxxxxxxxxSecured',
FIELDTERMINATOR = ',', ROWTERMINATOR = '\n', MAXERRORS = 500
);
GO
Error message:
Msg 4861, Level 16, State 1, Line 2
Cannot bulk load because the file "data/aaa/bbb/xxxxxxx.CSV" could not be opened. Operating system error code 32(The process cannot access the file because it is being used by another process.).
I have done the following...
Validated that I have internet connectivity from inside the docker container (-it ping google.com works after installing ping)
Validated that I properly have setup my credentialed connection to the storage account. I get different error messages if I mistype the path to the CSV file (file not found). I am using a private container in Azure Blob with a SAS key. I would presume this means that it can access and validate that the file exists.
Validated that there is nothing using port 10000 inside the container (using netstat running as root inside the container), this was based on several other SO questions with this error
Validated that I can do the exact same thing on my Mac running Docker for Mac and it works fine. But with Docker for Windows and Windows 10 as my host OS, it seems to not work.
Error: Operating system error code 32(The process cannot access the file because it is being used by another process.)
Starting with error, it will occur when another application is accessing the backup file and preventing SQL backup pro from writing to it.
**
Consider the following steps for alternative
**
Create the credentials
Check the following code block for creating the credentials
CREATE DATABASE SCOPED CREDENTIAL "Your storage account name"
WITH IDENTITY = 'SHARED ACCESS SIGNATURE',
SECRET = 'Your secret key';
Referring the blob location for dataset
CREATE EXTERNAL DATA SOURCE "your storage account name"
WITH (
TYPE = BLOB_STORAGE,
LOCATION = 'Mention your blob storage location',
CREDENTIAL = Your storage account name
);
The below code is for "Openrowset"
SELECT * FROM OPENROWSET(
BULK 'week3/inv-2017-01-19.csv',
DATA_SOURCE = 'MyAzureInvoices',
FORMAT = 'CSV',
FORMATFILE='invoices.fmt',
FORMATFILE_DATA_SOURCE = 'storage account name'
) AS DataFile;
Use Bulk Insert
BULK INSERT Colors2
FROM 'week3/inv-2017-01-19.csv'
WITH (DATA_SOURCE = 'Your storage account name', FORMAT = 'CSV');
Accessing data in CSV file using container
CREATE EXTERNAL DATA SOURCE Containername
WITH (
TYPE = BLOB_STORAGE,
LOCATION = https://newinvoices.blob.core.windows.net/datasetfoldername',
CREDENTIAL = Your sorage account name
);

Why this T-SQL query doesn't work in Synapse?

I am testing Synapse. I tried this query
SELECT
TOP 100 *
FROM
OPENROWSET(
BULK '<path to the parquet file>',
FORMAT='PARQUET'
) AS [result]
But I get the following error. How can I solve it?
Parse error at line: 4, column: 5: Incorrect syntax near 'OPENROWSET'.
That type of query would work in the serverless SQL pool, as per the documentation on OPENROWSET. It would not work in a dedicated SQL pool.
If you are in Synapse Studio, try changing the Connect to option to Built-in, which is the serverless engine. Optionally create a database to store objects like external data sources, external tables and views in:
Another easy way to generate a working OPENROWSET statement would be via Synapse Studio > Data hub (the little cylinder on the right), Linked > double-click your datalake to navigate to the parquet file you want to query > right-click it > SELECT TOP 100 ...

Macro VBA with Excel to insert/store image to MSQL Server

I have a folder with images (person photo) that need to be used in reporting and I want to save them in a SQL Server table. I am using SQL Server 2012 and I have created a table. I am neither an Admin(sa/dbo) nor I have permissions to use the BULK statement. I searched many sites but found none so far without BULK statement.
I have a userform developed in excel and using VBA to execute the insert query image to connect to sql with SSIS (if I am an admin the insert blob query executed successfully from my workstation) however if I am neither admin(sa/dbo) I tried using other workstation cause I have my sql server set up to allow access remotedly using tcp and open port 443. It fails to insert
Most people suggested using :
INSERT INTO PersonImage
SELECT * FROM
OPENROWSET(BULK "Imagepath", SINGLE_BLOB) AS image
I cannot use this or any statement with BULK in it. Could anyone of you suggest a way arround to load these images into the table with out using BULK INSERT statement?
Your help is appreciated!
Thanks and Regards

Bulk load permissions

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.

Resources