3

as the title says i'm trying to create triples using SPARQL queries from visualstudio. Using the same SPARQL queries inside stardog studio works, but when i try to send them from visualstudio using the stardogconnector i get the following error:

An unhandled exception of type 'VDS.RDF.Query.RdfQueryException' occurred in dotNetRDF.dll Additional information: A HTTP error (HTTP 400 Bad Request) occured while querying the Store. Store returned the following error message: {"message":"Cannot execute update query on read endpoint"} See aforementioned status line or inner exception for further details occurred

Here is the code:

StardogConnector stardog = new StardogConnector("http://localhost:5820", "dbtest", "admin", "password");
stardog.Begin();
string query = "INSERT DATA { <http://example/book1> dc:title \"test\"}";
stardog.Query(query);
stardog.Commit();

As i said, inserting the same query inside stardog studio gives the right result. The database is online, the connection works (password etc. is correct),... I just don't know what the error means. Can anybody help? I don't find much online about this error.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
  • THANK YOU for helping! stardog.Update(query); did the trick – Andrew Malcolm Dec 04 '18 at 16:42
  • 1
    Please don't edit the question title with "SOLVED", instead upvote and/or accept an answer. Or in this case, since the solution is in a comment, post an answer yourself. Thank you! – user247702 Dec 04 '18 at 16:46

2 Answers2

6

When query includes INSERT, UPDATE, or other write action, you have to change stardog.Query(query); (which is read-only) to stardog.Update(query); (which is apparently write-only).

TallTed
  • 9,069
  • 2
  • 22
  • 37
1

It appears that dotNetRdf sends all queries to the /myDb/query endpoint, however as of Stardog 5.x all SPARQL update queries must instead be sent to the /myDb/update endpoint. Official Stardog tools (Studio, stardog.js, etc.) were updated at that time.

Feel free to direct any other questions over at community.stardog.com.

snowell
  • 181
  • 2
  • 2
    [`.Query()`](http://www.dotnetrdf.org/api/html/M_VDS_RDF_Storage_BaseStardogConnector_Query.htm) does this, that's why there is an additional command [`.Update()`](http://www.dotnetrdf.org/api/html/M_VDS_RDF_Storage_StardogV2Connector_Update.htm) – UninformedUser Dec 04 '18 at 16:12