{"id":710,"date":"2014-03-21T18:53:11","date_gmt":"2014-03-21T18:53:11","guid":{"rendered":"http:\/\/elbsolutions.com\/projects\/?p=710"},"modified":"2022-02-03T11:25:02","modified_gmt":"2022-02-03T17:25:02","slug":"get-sharepoint-list-access-sql-server","status":"publish","type":"post","link":"https:\/\/elbsolutions.com\/projects\/get-sharepoint-list-access-sql-server\/","title":{"rendered":"Get Sharepoint List Access from SQL Server"},"content":{"rendered":"<p>Well, here I go &#8211; how to natively (or naively at this point &#8211; I just started this) manipulate Sharepoint Lists from SQL Server.<\/p>\n<p>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 &#8211; but there is a way around that too &#8211; 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 &#8211; another article will come soon regarding that.<\/p>\n<p>Basically &#8211; the onerous method would show that the two statements below work <!--more-->on an integrated networked environment &#8211; this was done FROM Sql Server (SSIS). Connection strings for <a href=\"https:\/\/www.connectionstrings.com\/sharepoint\/\" target=\"_blank\" rel=\"noopener noreferrer\">sharepoint are from this site<\/a> and the guy who suggested <a href=\"http:\/\/weblogs.sqlteam.com\/jhermiz\/archive\/2007\/08\/15\/60288.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">it is WAAAY down the comments list on this article<\/a> (look for Don Vineyard&#8217;s comment). Note that IMEX=1 means read only.<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nselect '1',*\r\nfrom\r\nOPENROWSET ('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};',\r\n 'SELECT * FROM LIST')\r\n\r\nselect '2',*\r\nfrom OPENROWSET ('Microsoft.ACE.OLEDB.12.0','WSS;IMEX=1;RetrieveIds=Yes;DATABASE=http:\/\/mysite.com\/somedirectory\/anotherdirectory\/;LIST={1d2d13c4-08cd-4068-8cc1-58b5d6d739e0};'\r\n, 'SELECT * FROM LIST')\r\n<\/pre>\n<p>Now that is quite basic. OPENROWSET does not accepta dynamic string so &#8230;<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n\r\nDECLARE @listnumber VARCHAR(100) = '2719FBBB%2D1C7F%2D4D64%2DAF55%2DC3E3A83378A8' --note I copied and pasted this from the URL\r\n\/* convert the url version to something usable - lets be lazy and let the computers do th work - make a function for this of course *\/\r\nSET @listnumber = REPLACE(@listnumber,'%7B','')\r\nSET @listnumber = REPLACE(@listnumber,'%2D','-')\r\nSET @listnumber = REPLACE(@listnumber,'%7b','')\r\nSET @listnumber = REPLACE(@listnumber,'%2d','-')\r\n\r\nPRINT @listnumber\r\n\r\nDECLARE\r\n@user VARCHAR(50) = 'DOMAIN\\my.username'\r\n, @password VARCHAR(50) = 'my_password'\r\n, @database VARCHAR(255) = 'http:\/\/mysite.com\/my_share\/point_root\/;LIST={' + @listnumber + '}'\r\n, @longSQL NVARCHAR(MAX)\r\n\r\n\/* Make the select statement being careful to use two single quotes '' when one is needed *\/\r\nSET @longSQL = N'select ''1'',*\r\nfrom\r\nOPENROWSET (''Microsoft.ACE.OLEDB.12.0'',''WSS;IMEX=1;RetrieveIds=Yes;User id=' + @user + ';Password=' + @password + ';DATABASE=' + @database + ';'',\r\n''SELECT * FROM LIST'')'\r\n\r\nPRINT @longSQL\r\n\r\nEXEC sp_executesql @longSQL\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>As for getting it to be a linked server .. this article is a start that I still have to investigate &#8230;<\/p>\n<p><a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/sqlserver\/en-US\/8d5d2945-90ab-4a78-9a10-ec77daf52cd3\/sharepoint-linked-server?forum=sqldatabaseengine\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/social.msdn.microsoft.com\/Forums\/sqlserver\/en-US\/8d5d2945-90ab-4a78-9a10-ec77daf52cd3\/sharepoint-linked-server?forum=sqldatabaseengine<\/a><\/p>\n<p>Others I have to vet are:<\/p>\n<ul>\n<li><a href=\"http:\/\/blog.nhaslam.com\/2012\/01\/26\/loading-reference-data-from-a-sharepoint-list-using-ssis\/\">http:\/\/blog.nhaslam.com\/2012\/01\/26\/loading-reference-data-from-a-sharepoint-list-using-ssis\/<\/a><\/li>\n<li><a href=\"http:\/\/www.mssqltips.com\/sqlservertip\/1733\/accessing-sharepoint-lists-with-sql-server-integration-services-ssis-2005\/\">http:\/\/www.mssqltips.com\/sqlservertip\/1733\/accessing-sharepoint-lists-with-sql-server-integration-services-ssis-2005\/<\/a><\/li>\n<li><a href=\"https:\/\/www.connectionstrings.com\/ace-oledb-12-0\/\">https:\/\/www.connectionstrings.com\/ace-oledb-12-0\/<\/a><\/li>\n<\/ul>\n<p>Links So Far:<\/p>\n<ul>\n<li><a href=\"http:\/\/nickgrattan.wordpress.com\/2008\/04\/29\/finding-the-id-guid-for-a-sharepoint-list\/\" target=\"_blank\" rel=\"noopener noreferrer\">Getting the List&#8217;s GUID is from the comment on this article.<\/a><\/li>\n<li><a href=\"http:\/\/macaalay.com\/2013\/11\/01\/how-to-archive-sharepoint-list-items-to-sql-server\/\" target=\"_blank\" rel=\"noopener noreferrer\">a guy who using Business Intelligence, SQL Server and Sharepoints harvests data from a Sharepoint list using .net.<\/a>\u00a0Step by Step guide<\/li>\n<li><a href=\"http:\/\/www.simplifiedsharepoint.com\/Pages\/EU\/Libraries.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">Sharepoint for dummies &#8211; a great resource for those getting started.<\/a><\/li>\n<li><a href=\"http:\/\/blogs.msdn.com\/b\/mind_talks\/archive\/2012\/04\/03\/sharepoint-list-from-sql-server-table-external-content-type-with-sharepoint-designer.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">Sharepoint Designer &#8211; using it to link to SQL Server<\/a><\/li>\n<li><a href=\"http:\/\/www.codeproject.com\/Articles\/33862\/Connecting-to-Database-Using-Custom-Webpart-in-Sha\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.codeproject.com\/Articles\/33862\/Connecting-to-Database-Using-Custom-Webpart-in-Sha<\/a>repoint 2007<\/li>\n<li><a href=\"http:\/\/sqlsrvintegrationsrv.codeplex.com\/releases\/view\/17652\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/sqlsrvintegrationsrv.codeplex.com\/releases\/view\/17652<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Well, here I go &#8211; how to natively (or naively at this point &#8211; 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,16,7],"tags":[],"class_list":["post-710","post","type-post","status-publish","format-standard","hentry","category-general","category-sqlserver_ssrs","category-windows"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Get Sharepoint List Access from SQL Server - ELB Solutions.com Inc.<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/elbsolutions.com\/projects\/get-sharepoint-list-access-sql-server\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get Sharepoint List Access from SQL Server - ELB Solutions.com Inc.\" \/>\n<meta property=\"og:description\" content=\"Well, here I go &#8211; how to natively (or naively at this point &#8211; 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 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/elbsolutions.com\/projects\/get-sharepoint-list-access-sql-server\/\" \/>\n<meta property=\"og:site_name\" content=\"ELB Solutions.com Inc.\" \/>\n<meta property=\"article:published_time\" content=\"2014-03-21T18:53:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-03T17:25:02+00:00\" \/>\n<meta name=\"author\" content=\"Etienne Bley\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Etienne Bley\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/get-sharepoint-list-access-sql-server\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/get-sharepoint-list-access-sql-server\\\/\"},\"author\":{\"name\":\"Etienne Bley\",\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/#\\\/schema\\\/person\\\/51e717c68f4f5917c63baf88f0896c39\"},\"headline\":\"Get Sharepoint List Access from SQL Server\",\"datePublished\":\"2014-03-21T18:53:11+00:00\",\"dateModified\":\"2022-02-03T17:25:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/get-sharepoint-list-access-sql-server\\\/\"},\"wordCount\":535,\"articleSection\":[\"General\",\"SQLServer_SSRS\",\"Windows\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/get-sharepoint-list-access-sql-server\\\/\",\"url\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/get-sharepoint-list-access-sql-server\\\/\",\"name\":\"Get Sharepoint List Access from SQL Server - ELB Solutions.com Inc.\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/#website\"},\"datePublished\":\"2014-03-21T18:53:11+00:00\",\"dateModified\":\"2022-02-03T17:25:02+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/#\\\/schema\\\/person\\\/51e717c68f4f5917c63baf88f0896c39\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/get-sharepoint-list-access-sql-server\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/get-sharepoint-list-access-sql-server\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/get-sharepoint-list-access-sql-server\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get Sharepoint List Access from SQL Server\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/#website\",\"url\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/\",\"name\":\"ELB Solutions.com Inc.\",\"description\":\"Bringing all your IT Pieces together\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/#\\\/schema\\\/person\\\/51e717c68f4f5917c63baf88f0896c39\",\"name\":\"Etienne Bley\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f8971dfb65b25b768415568f83247df4057f15d037137e386928a804e2c997b9?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f8971dfb65b25b768415568f83247df4057f15d037137e386928a804e2c997b9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f8971dfb65b25b768415568f83247df4057f15d037137e386928a804e2c997b9?s=96&d=mm&r=g\",\"caption\":\"Etienne Bley\"},\"url\":\"https:\\\/\\\/elbsolutions.com\\\/projects\\\/author\\\/etienne-bley\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get Sharepoint List Access from SQL Server - ELB Solutions.com Inc.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/elbsolutions.com\/projects\/get-sharepoint-list-access-sql-server\/","og_locale":"en_US","og_type":"article","og_title":"Get Sharepoint List Access from SQL Server - ELB Solutions.com Inc.","og_description":"Well, here I go &#8211; how to natively (or naively at this point &#8211; 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 [&hellip;]","og_url":"https:\/\/elbsolutions.com\/projects\/get-sharepoint-list-access-sql-server\/","og_site_name":"ELB Solutions.com Inc.","article_published_time":"2014-03-21T18:53:11+00:00","article_modified_time":"2022-02-03T17:25:02+00:00","author":"Etienne Bley","twitter_misc":{"Written by":"Etienne Bley","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/elbsolutions.com\/projects\/get-sharepoint-list-access-sql-server\/#article","isPartOf":{"@id":"https:\/\/elbsolutions.com\/projects\/get-sharepoint-list-access-sql-server\/"},"author":{"name":"Etienne Bley","@id":"https:\/\/elbsolutions.com\/projects\/#\/schema\/person\/51e717c68f4f5917c63baf88f0896c39"},"headline":"Get Sharepoint List Access from SQL Server","datePublished":"2014-03-21T18:53:11+00:00","dateModified":"2022-02-03T17:25:02+00:00","mainEntityOfPage":{"@id":"https:\/\/elbsolutions.com\/projects\/get-sharepoint-list-access-sql-server\/"},"wordCount":535,"articleSection":["General","SQLServer_SSRS","Windows"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/elbsolutions.com\/projects\/get-sharepoint-list-access-sql-server\/","url":"https:\/\/elbsolutions.com\/projects\/get-sharepoint-list-access-sql-server\/","name":"Get Sharepoint List Access from SQL Server - ELB Solutions.com Inc.","isPartOf":{"@id":"https:\/\/elbsolutions.com\/projects\/#website"},"datePublished":"2014-03-21T18:53:11+00:00","dateModified":"2022-02-03T17:25:02+00:00","author":{"@id":"https:\/\/elbsolutions.com\/projects\/#\/schema\/person\/51e717c68f4f5917c63baf88f0896c39"},"breadcrumb":{"@id":"https:\/\/elbsolutions.com\/projects\/get-sharepoint-list-access-sql-server\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/elbsolutions.com\/projects\/get-sharepoint-list-access-sql-server\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/elbsolutions.com\/projects\/get-sharepoint-list-access-sql-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/elbsolutions.com\/projects\/"},{"@type":"ListItem","position":2,"name":"Get Sharepoint List Access from SQL Server"}]},{"@type":"WebSite","@id":"https:\/\/elbsolutions.com\/projects\/#website","url":"https:\/\/elbsolutions.com\/projects\/","name":"ELB Solutions.com Inc.","description":"Bringing all your IT Pieces together","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/elbsolutions.com\/projects\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/elbsolutions.com\/projects\/#\/schema\/person\/51e717c68f4f5917c63baf88f0896c39","name":"Etienne Bley","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f8971dfb65b25b768415568f83247df4057f15d037137e386928a804e2c997b9?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f8971dfb65b25b768415568f83247df4057f15d037137e386928a804e2c997b9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f8971dfb65b25b768415568f83247df4057f15d037137e386928a804e2c997b9?s=96&d=mm&r=g","caption":"Etienne Bley"},"url":"https:\/\/elbsolutions.com\/projects\/author\/etienne-bley\/"}]}},"_links":{"self":[{"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/posts\/710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/comments?post=710"}],"version-history":[{"count":13,"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/posts\/710\/revisions"}],"predecessor-version":[{"id":2814,"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/posts\/710\/revisions\/2814"}],"wp:attachment":[{"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/media?parent=710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/categories?post=710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elbsolutions.com\/projects\/wp-json\/wp\/v2\/tags?post=710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}