Well, here I go – how to natively (or naively at this point – I just started this) manipulate Sharepoint Lists from SQL Server.
I did it! It is not using a linked server (I will get to the bottom of that though) but using an OPENROWSET works. This means that the user needs to have insert and select privileges – but there is a way around that too – by making a role/user internal to the dB and running the stored proc run (EXECUTE AS) that role/user. To get that to work takes some tinkering – another article will come soon regarding that.
Basically – the onerous method would show that the two statements below work on an integrated networked environment – this was done FROM Sql Server (SSIS). Connection strings for sharepoint are from this site and the guy who suggested it is WAAAY down the comments list on this article (look for Don Vineyard’s comment). Note that IMEX=1 means read only.
[sql]
select ‘1’,*
from
OPENROWSET (‘Microsoft.ACE.OLEDB.12.0′,’WSS;IMEX=1;RetrieveIds=Yes;User id=MYDOMAIN\username;Password=*********;DATABASE=http://mysite.com/somedirectory/anotherdirectory/;LIST={1d2d13c4-08cd-4068-8cc1-58b5d6d739e0};’,
‘SELECT * FROM LIST’)
select ‘2’,*
from OPENROWSET (‘Microsoft.ACE.OLEDB.12.0′,’WSS;IMEX=1;RetrieveIds=Yes;DATABASE=http://mysite.com/somedirectory/anotherdirectory/;LIST={1d2d13c4-08cd-4068-8cc1-58b5d6d739e0};’
, ‘SELECT * FROM LIST’)
[/sql]
Now that is quite basic. OPENROWSET does not accepta dynamic string so …
[sql]
DECLARE @listnumber VARCHAR(100) = ‘2719FBBB%2D1C7F%2D4D64%2DAF55%2DC3E3A83378A8′ –note I copied and pasted this from the URL
/* convert the url version to something usable – lets be lazy and let the computers do th work – make a function for this of course */
SET @listnumber = REPLACE(@listnumber,’%7B’,”)
SET @listnumber = REPLACE(@listnumber,’%2D’,’-‘)
SET @listnumber = REPLACE(@listnumber,’%7b’,”)
SET @listnumber = REPLACE(@listnumber,’%2d’,’-‘)
PRINT @listnumber
DECLARE
@user VARCHAR(50) = ‘DOMAIN\my.username’
, @password VARCHAR(50) = ‘my_password’
, @database VARCHAR(255) = ‘http://mysite.com/my_share/point_root/;LIST={‘ + @listnumber + ‘}’
, @longSQL NVARCHAR(MAX)
/* Make the select statement being careful to use two single quotes ” when one is needed */
SET @longSQL = N’select ”1”,*
from
OPENROWSET (”Microsoft.ACE.OLEDB.12.0”,”WSS;IMEX=1;RetrieveIds=Yes;User id=’ + @user + ‘;Password=’ + @password + ‘;DATABASE=’ + @database + ‘;”,
”SELECT * FROM LIST”)’
PRINT @longSQL
EXEC sp_executesql @longSQL
[/sql]
As for getting it to be a linked server .. this article is a start that I still have to investigate …
Others I have to vet are:
- http://blog.nhaslam.com/2012/01/26/loading-reference-data-from-a-sharepoint-list-using-ssis/
- http://www.mssqltips.com/sqlservertip/1733/accessing-sharepoint-lists-with-sql-server-integration-services-ssis-2005/
- https://www.connectionstrings.com/ace-oledb-12-0/
Links So Far:
- Getting the List’s GUID is from the comment on this article.
- a guy who using Business Intelligence, SQL Server and Sharepoints harvests data from a Sharepoint list using .net. Step by Step guide
- Sharepoint for dummies – a great resource for those getting started.
- Sharepoint Designer – using it to link to SQL Server
- http://www.codeproject.com/Articles/33862/Connecting-to-Database-Using-Custom-Webpart-in-Sharepoint 2007
- http://sqlsrvintegrationsrv.codeplex.com/releases/view/17652