3

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.

Community
  • 1
  • 1
Ondrej Peterka
  • 3,349
  • 4
  • 35
  • 49
  • It may be worth adding the MySQL tag to the question as this appears to be a feature specific to MySQL? – qujck Jun 13 '13 at 14:34
  • No, the underlying DB is MS SQL 2008 R2. – Ondrej Peterka Jun 13 '13 at 19:51
  • 1
    Ah, that makes things a lot clearer. The link in your post is MySQL specific. – qujck Jun 13 '13 at 20:14
  • 1
    Thanks @qujck. I missed that somehow (even if it is directly in the title!). So I guess there is no way for SQL server, which is a shame. Please adjust your answer, so I can mark it as the correct answer. – Ondrej Peterka Jun 13 '13 at 20:19

1 Answers1

4

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

qujck
  • 14,388
  • 4
  • 45
  • 74
  • 2
    Thanks for the tip. Unfortunatelly it is neither of `Command` or `Connect Timeout`. Still the same exception. You probably meant `Connection Timeout=60;`. However, that deasl with connection timeout not with how long the query should wait to be finished (which is what CommandTimeout is supposed to do). – Ondrej Peterka Jun 13 '13 at 12:58