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.

4
  • It may be worth adding the MySQL tag to the question as this appears to be a feature specific to MySQL? Commented Jun 13, 2013 at 14:34
  • No, the underlying DB is MS SQL 2008 R2. Commented Jun 13, 2013 at 19:51
  • 1
    Ah, that makes things a lot clearer. The link in your post is MySQL specific. Commented Jun 13, 2013 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. Commented Jun 13, 2013 at 20:19

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.