This is a migrated thread and some comments may be shown as answers.

Info regarding multithreaded sql statements

1 Answer 52 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Norbert
Top achievements
Rank 2
Norbert asked on 02 Dec 2011, 11:06 AM
Hello,

I want to exec sql statements in multithreaded environment. When you look for the following example - why are there several Sql Statements like SET LOCK_TIMEOUT etc?
internal class Program
    {
 
        public static int i=0;
        public static Object lockvar = ""; // Lock-Variable
 
        private static void Main(string[] args)
        {
            CheckTime("Initialize Application");
            AppInitializer.InitializeApp();
             
            Task t1 = new Task(DoIt);
            Task t2 = new Task(DoIt);
            Task t3 = new Task(DoIt);
            t1.Start();
            t2.Start();
            t3.Start();
 
            Task.WaitAll(t1, t2, t3);
            Console.WriteLine("The end");
            Console.ReadLine();
        }
 
        public static void DoIt()
        {
            Thread.Sleep(2000); //simulate longer running task...
            lock ( lockvar )
            {
                string mystring = "Thread started... ";
                i++;
                mystring += i;
                CheckTime(mystring);
                using ( IRepository<SysProperty> rep = App.Instance.GetService<IRepository<SysProperty>>() )
                {
                    rep.AutoCommit = false;
                    var o = rep.AdoGetSql("Select * From dbo.tblSysProperty where name = 'DbVersion'");
                    CheckTime(o.First().Name.ToString());
                    o.First().Value = "Testwert " + i.ToString();
                    rep.SaveChanges();
                    Console.WriteLine(rep.LogOutput);
                }
                //Repository.SaveChanges();
                System.Console.WriteLine("Alles gespeichert...{0}", i.ToString());
            }
        }
 
        private static void CheckTime(string Info)
        {
            Console.WriteLine("{0} | {1}", DateTime.Now.ToString("u"), Info.ToString());
        }
    }

How does OA handle that?
FYI: I am using one context (in this case a repository around the OA context) per thread (task in TPL)

Thank you in advance,
Norbert

1 Answer, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 05 Dec 2011, 10:03 AM
Hello Norbert,
We are setting the lock timeout once we open a connection. Because the connection is pooled, this extra call happens only one in it's lifetime. There are some more statements executed when you use your first context. If you use our high-low key generator, we check if the content of the extra table looks good.

All the best,
Jan Blessenohl
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

Tags
General Discussions
Asked by
Norbert
Top achievements
Rank 2
Answers by
Jan Blessenohl
Telerik team
Share this question
or