Transactions with YCQL using C#

Hi there,

I’m using the C# client library at the following page:

How does one use transactions with that library against YugaByte?

I’ve looked through the documentation and don’t see an example.

hi @Exocomp

Through the YCQL API, we support a limited form of multi-row/multi-table transactions using the


like syntax.


While the examples in the above link use Java, it would be pretty similar in C# as well as the statement is handled by the server-side (so the usual prepare/bind/execute model will work just fine).

NOTE: the BEGIN … END isn’t as general as flexible as the say an anonymous PL/SQL or PLPGSQL like syntax. So you CANNOT intersperse arbitrary control flow (while loops, if () then … else … ) etc.

If you need more flexible transaction control, you can do multi-step client-controlled transactions through our YSQL API (which is currently in Beta).

Would love to learn a bit more about your use case (if you are open to it) and understand how you are planning to use transactions.




Thanks for the link that helps.

I’m currently using a batch statement to insert two records, for ex:

var batch = new BatchStatement()

The two records are related so if the second fails to add for any reason then the first should rollback. Which is why I wanted to use a transaction, am I right to use it in that using a batch statement there is a possibility the second could fail?

I think the example you provided will work fine for my needs. Sounds like I need to create a prepared statement with the begin/end and the two statements together and then just execute it.

That is correct @exocomp. You need to put the two statements in a single BEGIN … END statement and then just execute it (and you can still use the Bind (?) placeholders to avoid recompiling the statements each time).