NHibernate/Active Record – StaleStateException?

Absurdes, IT No Comments »

Today I had to use an Ative Record implementation for C#: Castle Active Record. It worked verfy fine until i needed to save a one to many relationship. Then the underlying NHibernate yielded the following Exception:
StaleStateException: unexpected row count -1 expected 1 .

Googling for that Exception gave me two options: At first, turning the sql servers NOCOUNT property OFF by either sending “SET NOCOUNT OFF” or setting the appropriate property of the SQL-Server in the config dialog. Both did not work for me, as i am neither the Admin of the server nor i can send the command by hand through the many layers introduced by ActiveRecord/NHibernate.

Another possible solution was overriding the connection driver to let i send the query everytime the connection gets requested. This was proposed by the blog author of: http://www.socialanimal.com/archives/2008/03/07/nhibernate-and-nocount/. This either didn’t work for me.

But taking a look in the database suprised me! My Data was actually written! So a simply try {} catch(…) { //ignore } did the job!

SHAME ON ME FOR THAT :-)

Base64 En-/Decoding using OpenSSL in C

IT, UNI Kommentare deaktiviert

Recently i had to implement Base64 en & decoding using openssl’s bio library, which by the way is just great, but a little “under-documented!”

If you ever wondered, why the standard example of decoding base64 data always returns 0 when using it with your test data? Well there is some nice undocumented feature: Strings that do not end with a newline ‘\n’ are not processed! So you have two possibilities: adding a newline to the string or use the following flag:

BIO_set_flags(BIO* to your bio_f_base64, BIO_FLAGS_BASE64_NO_NL);

Edit: 21/Dec/08:

After handin of the courses homework i can now give some details about how to do it:

Using a chain of BIO filters is the most flexible way to handle proper base64 en-/decoding:


//write base64 coded data to stdout
BIO* b64 = BIO_new(BIO_f_base64());
BIO* bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
bio_out = BIO_push(b64, bio_out); //attach output bio to base64 bio
BIO_write(bio_out,"data",sizeof("data"));
BIO_flush(bio_out); //flush the buffer
BIO_free_all(bio_out); //cleanup!

For more information see the super perfect documentation: http://www.openssl.org/docs/crypto/BIO_f_base64.html

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS