Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Using Credentials with OPENROWSET

$
0
0

I am trying to use an OPENROWSET to access an excel file that is located on a shared drive in order to import the data. I cannot place the file on the SQL Server Machine, so I need to access using the shared drive. I had assumed a Credential would provided the needed access to that file, but cannot determine the syntax. The below gives me the error: Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.'  How can I access the file on the shared drive using OPENROWSET?

INSERT INTO tbl_tempImport 
   SELECT * 
   FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
                   'Excel 12.0;Database=//vm/folder/file.xlsx;HDR=YES',
                   'SELECT * FROM [Sheet1$]')
   WITH CREDENTIAL MyCredential

EDIT Attempt as suggested by RSingh():::

Attempted using a proxy. Created CREDENTIAL as SharedDriveAccess and proxy as SharedDriveAccess

Below SQL yields error "

Msg 102, Level 15, State 1, Line 7
Incorrect syntax near 'SharedDriveAccess'.

"

INSERT INTO tbl_tempImport 
   SELECT * 
   FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
                   'Excel 12.0;Database=//vm/folder/file.xlsx;HDR=YES',
                   'SELECT * FROM [Sheet1$]') EXECUTE AS 'SharedDriveAccess'


EDIT Attempt as suggested by pituach:::

Attempted including credentials in OPENROWSET criteria. Did not change or resolve original error.

INSERT INTO tbl_tempImport 
   SELECT * 
   FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
                   'Excel 12.0;Database=//vm/folder/file.xlsx;HDR=YES;UID=user;PWD=pass',
                   'SELECT * FROM [Sheet1$]')


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>