我正在尝试为dbcommand设置超时,并测试它是超时设置为1的原因。
这是我正在使用的代码,但是超时永远不会触发,我做错了吗?
注意:使用DbConnection是因为此代码是通用代码的摘录,不仅用于db2,因此db2connection不是一个选项。
String lProviderFactory = "System.Data.OleDb";
String lStrConexion = "Provider=IBMDADB2;Database=PYRAMID;Hostname=192.9.200.13;Protocol=TCPIP; Port=50000;Uid=db2admin;Pwd=xxx;";
String lQuery = "SLOW SELECT";
var lDbFactory = DbProviderFactories.GetFactory(lProviderFactory);
DbConnection mConexion = lDbFactory.CreateConnection();
mConexion.ConnectionString = lStrConexion;
mConexion.Open();
try
{
DbCommand lComando = mConexion.CreateCommand();
lComando.CommandText = lQuery;
lComando.CommandTimeout = 1;
DbDataAdapter lAdapter = lDbFactory.CreateDataAdapter();
lAdapter.SelectCommand = lComando;
DataSet lDs = new DataSet();
lAdapter.Fill(lDs);
}
catch(Exception ex)
{
Console.WriteLine("EXCEPCION :" + ex.Message); //Timeout should fall in here
}
finally
{
mConexion.Close();
}
谢谢!