Saturday 22 December 2012

A read lock may not be acquired with the write lock, Error retrieving values from ObjectStateEntry. See inner exception for details. held in this mode.

Today , i've got this error when trying to insert record in new database.
I'm using entity framework 4.1, code first approach.

A read lock may not be acquired with the write lock,
Error retrieving values from ObjectStateEntry. See inner exception for details.

At first glance, i've thought that there's a current transaction that locks the access on the table when trying to insert a new record. So i check all actives transactions but any of them get a lock on my table.
As I use a transactionscope during the insert operation, i've removed them but the issue still not resolved.

Stop, I decided to go in deeper in the error message , that was the first thing that I had to do....

Take a close look on the InnerException.InnerException object.


Everything becomes clear now. there a violation of constraint that entity framework has detected and it raises an error when constraint has been violated.
Once those constraint have been updated, the problem is resolved !!!


Wednesday 19 December 2012

My old vw combi split bus


NHibernate tunning

 private static ISessionFactory CreateSessionFactory1()
        {
            return Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("Sql2008")))
                //.Cache(c=>c.UseSecondLevelCache().ProviderClass(typeof(NHibernate.Caches.SysCache.SysCacheProvider).AssemblyQualifiedName))               
                //.Cache(c => c.UseQueryCache().ProviderClass(typeof(NHibernate.Caches.SysCache.SysCacheProvider).AssemblyQualifiedName))                               
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>())
                .BuildConfiguration()

            #region cache configuration
                .SetProperty(NHibernate.Cfg.Environment.UseSecondLevelCache, "true")
                .SetProperty(NHibernate.Cfg.Environment.UseQueryCache, "true")
                .Cache(c =>
                {
                    c.Provider<NHibernate.Caches.SysCache.SysCacheProvider>();
                    //    c.DefaultExpiration = 1;
                })
            #endregion
            #region configure cache on Movies Entity
            .EntityCache<Movies>(c =>
            {
                c.Strategy = EntityCacheUsage.ReadWrite;
                c.RegionName = "Region1";
            })
                        #endregion
            .BuildSessionFactory();
        }
      

   using (var session = sessionFactory.OpenSession())
           {
               // var m8 = session.CreateCriteria(typeof(Movies)).Add(Restrictions.Eq("Genre", "Guerre1234")).UniqueResult<Movies>();
               //var m8 = session.Get<Movies>(2);
               var m8 = session.CreateQuery("from Parent10 p where p.id1 =: id1 and p.id2 =: id2")
                       .SetString("id1", "1")
                       .SetString("id2", "2")
                       .SetCacheable(true)
                       .SetCacheRegion("Region1")
                       .Future<Parent10>()
                       //.Enumerable<Parent10>()
                       .First<Parent10>();
              // Console.WriteLine("Id > " + m8.id1 + "Genre > " + m8.id2 + " Price >  " + m8.ParentName);

               //Console.ReadLine();
              // m8.Price = 2; session.Flush();
              // session.Close();
               Console.WriteLine("End Session 1");
           }
           using (var session = sessionFactory.OpenSession())
           {
               //var m8 = session.CreateCriteria(typeof(Movies)).Add(Restrictions.Eq("Genre", "Guerre1234")).UniqueResult<Movies>();
               var m8 = session.CreateQuery("from Parent10 p where p.id1 =: id1 and p.id2 =: id2")
                       .SetString("id1", "1")
                       .SetString("id2", "2")
                       .SetCacheable(true)
                       .SetCacheRegion("Region1")
                       .Future<Parent10>()
                       //.Enumerable<Parent10>()
                       .First<Parent10>();
             //  Console.WriteLine("Id > " + m8.id1 + "Genre > " + m8.id2 + " Price >  " + m8.ParentName);
               var m9 = session.CreateQuery("from Parent10 p where p.id1 =: id1 and p.id2 =: id2")
                      .SetString("id1", "1")
                      .SetString("id2", "3")
                      .SetCacheable(true)
                      .SetCacheRegion("Region1")
                      .Future<Parent10>()
                   //.Enumerable<Parent10>()
                      .First<Parent10>();
               Console.Read();
               var m10 = session.CreateQuery("from Parent10 p where p.id1 =: id1 and p.id2 =: id2")
                      .SetString("id1", "1")
                      .SetString("id2", "2")
                      .SetCacheable(true)
                      .SetCacheRegion("Region1")
                      .Future<Parent10>()
                   //.Enumerable<Parent10>()
                      .First<Parent10>();
              // Console.ReadLine();
               //session.Close();
               Console.WriteLine("End Session 2");
           }

Wednesday 14 November 2012

Define a column as guid as type

A quick tips to define a column as a guid

create table DevenvaGuidTips (
guid uniqueidentifier PRIMARY KEY DEFAULT NEWSEQUENTIALID() ROWGUIDCOL
,.....



MSDN :
Unlike columns defined with the IDENTITY property, the Database Engine does not automatically generate values for a column of type uniqueidentifier. To insert a globally unique value, create a DEFAULT definition on the column that uses the NEWID or NEWSEQUENTIALID function to generate a globally unique value

Saturday 18 August 2012

Devenva becomes a delivery centre on Microsoft technologies.

 

Recupérer la valeur d'une propriété privée - Get the value of private property outside the containing assembly via reflection( French version )

Récupérer la valeur d'une propriété privée d'une classe à partir d'une autre classe est, par théorie, impossible. En effet, par définition, une propriété déclarée private n'est accessible qu'à l'intérieur de la classe.
Considérons l'exemple :

 public class Person
    {
        public Personne(string name, string surname)
        {
            Name = name;
            Surname = surname;
        }
        public string  Name { get; set; }
        private string Surname { get; set; }
    }
Depuis une autre classe, il est impossible d'évoquer :

Person holder = new Person("Foo","Bar");
var holderName = holder.Name ; //right
var holderSurname = holder.Surname ; // error

Toutefois dans certains cas exceptionnels, nous voulons récupérer cette valeur. Etant donné que le source de l'assembly n'est pas disponible, voici une façon de récupérer la valeur :

 var holderSurname = p.GetType().GetProperty("Surname", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(p, null);

Conclusion : à partir de la réflexion, nous avons pu avoir la valeur d'une propriété privée d'une classe.



Saturday 28 January 2012

SQL Server : Unicode / Non Unicode Data types

I write this topic to give you a quick tips when you're facing to some errors messages like 'cannot convert unicode to non unicode ....'
In SQL Server, unicode character is encoded in 2 bytes rather than 1 byte for a non unicode character.
In SQL Server, unicoded datas type are prefixed by 'n' : nvarchar, nchar, ntext (deprecated because will be remove in later version of sql server).
They are the same as varchar, nchar,text except that :
- they can handle up to 4000 characters  instead of 8000 characters for varchar,char,text.
- take more memory space
- can support a wider range of characters.

Sometimes in SSIS, the source is captured as a DT_STR ( non unicode ). A classic problem is that the table column is set to nvarchar ( unicode ) data type. A problem occurs when executing the task.
To resolve that issue, 2 solutions :
1- change the table column data type to varchar ( non unicode ) - it's working but I think that it's a dummy and dirty solution.
2- create a temporary output column of type DT_WSTR ( unicoded ), code some inputprocessrow business logic  and map the table column of type nvarchar to that temporary column.

Saturday 7 January 2012

Mango unlock - Please check that the Zune software is running and that Zune's sync partnership with your phone has been established - Resolved

Hi all windows phone users :
Today, I have to re-unlock my windows phone 7 with the new firmware Mango 7.5. I've noticed that the phone became locked after the Mango update.

During the unlocking process, I've this error message : 
Please check that the Zune software is running and that Zune's sync partnership with your phone has been established 

The guys from yallapps told me that I must uninstall and reinstall the Zune software. Once done, the same issue occurs and finally I decide to handle the problem myself.

First of all, it's impossible that this is due to Zune because i've the last version.

After seeing the behavior of message display in the unlock popup, the error fires after the message " connect to the phone ..." is displayed.
But Zune can connect to my phone, as proof, a sync was successfully done just after connecting the phone to my pc.

So, it seems that there's something blocking at the connection when the phone is sending data to outside.
At this time, I verify that any internet connection cant be made from the phone by using the usb .


Solution
I  switched the connection provider to use the mobile network 3G+ instead of using the usb connection and after redoing the registration process, the problem was solved.  My phone is now dev unlocked