1

I'm having difficulty accessing data in a text file via OPENROWSET. The file is saved locally. I'm raising the error which seems to be related to the location of the file but I'm really confused as to why SQL Server cant find it.

Msg 12704, Level 16, State 1, Line 3 Bad or inaccessible location specified in external data source "(null)".

I'm using UNC naming convention. And I've double checked the file name & location are in fact correct & the file does contain data.

Can anyone please help me correct this T-SQL so that I can access the file via OPENROWSET?

DECLARE @json_data VARCHAR(MAX)

SELECT @json_data = BulkColumn FROM OPENROWSET(BULK'\\LAPTOP-14K308TA\C$\Users\EB\Desktop\Python Files\comp_data.json', SINGLE_BLOB) JSON;

SELECT @json_data as SingleRow_Column

IF (ISJSON(@json_data) = 1)
    BEGIN 
        PRINT 'Imported JSON is valid'
    END
ELSE
    BEGIN 
        PRINT 'Invalid JSON imported'
    END
GO
7
  • The the user running the query have access to that path and can see it? Commented May 13, 2019 at 19:11
  • Yes the user has access to the path & can open the file manually. Commented May 13, 2019 at 19:15
  • Don't think that is a valid UNC path - the 2nd element must be a share and "C:" is not a share. You can (but probably should not) use the adminstrative share "C$". And it is still not clear if the path you want to use is local to the the machine running your instance (and executing the query) or local to the person running this query. Nor is it clear what you mean by "the user has access ...". It is the service account of your instance which needs permissions - but that is irrelevant now. Commented May 13, 2019 at 19:23
  • apologies, the user is me and I'm not running this query on a remote SQL Server instance, I'm executing it locally.i've tried that & thats also not working Commented May 13, 2019 at 19:28
  • If SQL is local, and so is the file, then use local path. C:\Users\EB\Desktop\Python Files\comp_data.json. Commented May 14, 2019 at 3:14

1 Answer 1

1

Turns out the file location was incorrect, fixing the file location solved the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.