How to set Entity framework 4 CommandTimeout in connection string?

10,532

I don't believe it's possible to set the command timeout in the connection string.

The Command is different object to the connection. A Command can have a connection but it has its own timeout that you can set.

Your example link above is MySQL specific ...

See here

Share:
10,532
Ondrej Peterka
Author by

Ondrej Peterka

I simply like programming. I do it for living as well as for my enjoyment. I am working mainly in C#, Java, C\C++, Objective-C and Javascript. I have also programmed with Typescript, Scala, F#, Haskell or even Cayenne.

Updated on June 05, 2022

Comments

  • Ondrej Peterka
    Ondrej Peterka almost 2 years

    Is it possible to specify commandTimeout in connection string in app.config?

    According to this SO question: Entity Framework with MySQL - Timeout Expired while Generating Model the following should work:

      <add name="DataEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=XXXX;initial catalog=XXXXX2;persist security info=True;user id=XXXXX;password=XXXXX;multipleactiveresultsets=True;App=EntityFramework;Default Command Timeout=12;&quot;" providerName="System.Data.EntityClient" />
    

    However, it does not work - exception is thrown saying that Default Command Timeout is not known part of connection string.

    If I do this directly in code using the following code, it works fine:

            var db = new DataEntities(); // ObjectContext
            db.CommandTimeout = 1;
    

    Does anybody know how to set the commandTimeout using connectionstring or other native option in config?

    Thank you.