Is there a sample on how to execute a raw SQL command?

This could be useful to execute DB-specific stored procedures * check right grants on DB * check DB configuration * execute backup * ...


Updated at 19.04.2010 8:29:34

Thanks for your reply : this is exactly what I need!

Shame on me for not finding it in the manual ;)

By the way, where wan I find the latest manual? http://dataobjectsdotnet.googlecode.com/hg/Manual/?

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Apr 16 '10 at 14:23

olorin's gravatar image

olorin
358848792

Hello olorin,

check out this one: http://goo.gl/dJvg

Actually, it is a test, but it is meaningful enough to demonstrate the approach.

(Apr 16 '10 at 14:23) Dmitri Maximov Dmitri%20Maximov's gravatar image

This part is already described in Manual: http://goo.gl/Kauk

(Apr 16 '10 at 14:23) Alex Yakunin Alex%20Yakunin's gravatar image

Yes, you are definitely right.

(Apr 16 '10 at 14:23) Dmitri Maximov Dmitri%20Maximov's gravatar image

One Answer:

For further reference this might be an example the manual lacks:

var directSql = session.Services.Demand<DirectSqlAccessor>();
if (!directSql.IsAvailable)
  throw new NotSupportedException(
    "DirectSqlAccessor is not available: " +
    "indexing storage provider (e.g. memory) is used.");

var command = directSql.CreateCommand();
command.CommandText = "select * from Customers";
var reader = command.ExecuteReader();
if (reader.HasRows) {
  while (reader.Read)
    Console.WriteLine(reader.Item(0).ToString);
}

answered Oct 08 '10 at 08:42

Michiel%20Alders's gravatar image

Michiel Alders
506710

edited Oct 08 '10 at 12:51

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

Sorry, it seems Dmitri and I did really wrong thing by providing a reference to test code in comments.

Thank you for your answer. I'll beautify it a bit.

(Oct 08 '10 at 09:19) Alex Yakunin Alex%20Yakunin's gravatar image

I just fixed the example code after looking up the code in Manual - DirectSqlAccessor is a service that must be acquired via our IoC container (Session.Services). Also, it's better to check if underlying backend is available.

(Oct 08 '10 at 12:51) Alex Yakunin Alex%20Yakunin's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×573

Asked: Apr 16 '10 at 14:23

Seen: 2,630 times

Last updated: Oct 08 '10 at 12:51

powered by OSQA