Вопрос

Is there a possibility to change the connection timeout when we are using System.data.Common.DbProviderFactory?

Это было полезно?

Решение 2

Yes, check your connectionString to see if everything is fine to access the Database.

A DBProviderFactory instance just return the abstrations of the System.Data.Common. The real type comes from your ado.net provider (SqlClient, OracleClient, etc.).

When you do something like:

IDbConnection connection = dbFactory.CreateConnection();
connection.Open();

The connection object is an abstration but the dbFactory.CreateConnection() will return a concrete type of OracleConnection or SqlConnection as your provider.

Другие советы

For those who really are trying to change the connection timeout, not the command timeout, as I was when Google brought me to this page, you can do so by adding a Connection Timeout attribute to your connection string:

"DATA SOURCE=localhost:1521/mydatabase;USER ID=MY_USERNAME;PASSWORD=mypassword;Connection Timeout=60"

You were probably trying to set a command time out. Connection timeout is how long the computer will look for a server before giving up and deciding the db server is down.

Command time out is how long you want a query to run before you want it to give up waiting for the query to finish.

ref: http://msdn.microsoft.com/en-us/library/system.data.common.dbcommand.commandtimeout(v=vs.110).aspx

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top