SCM

[#1010666] CommandTimeout does gets reset to 20 when a Connection object is assigned to it

View Trackers | Bugs | Download .csv | Monitor

Date:
2009-07-01 14:25
Priority:
3
State:
Open
Submitted by:
Debabrata Das (maverik)
Assigned to:
Nobody (None)
Npgsql Version:
2.0
Category:
Group:
Resolution:
None
Summary:
CommandTimeout does gets reset to 20 when a Connection object is assigned to it

Detailed description
CommandTimeout value of a NpgsqlCommand is reset to the default value for commandTimeout (i.e. 20 seconds) when a NpgsqlConnection object is assigned to it.

Here is the code to reproduce it:

NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=user1;Password=secret;Database=testdb1;");

NpgsqlCommand command = new NpgsqlCommand();
command.CommandTimeout = int.MaxValue;
command.CommandText = "insert into table1 values(1, 1)";

Console.WriteLine(command.CommandTimeout); // 2147483647

command.Connection = conn; // assigning connection
Console.WriteLine(command.CommandTimeout); // 20


So researching bought out that the issue is in the NpgsqlCommand class code. As shown below:

public NpgsqlConnection Connection
{
get
{
............
............
............
}
set{
............
............
............


this.connection = value;
Transaction = null;
if (this.connection != null)
connector = this.connection.Connector;

SetCommandTimeout();

............
............
}

And here is the SetCommandTimeout()code:

private void SetCommandTimeout()
{
if (Connector != null)
timeout = Connector.CommandTimeout; // this should check if the command has any CommandTimeout specified
timeout = ConnectionStringDefaults.CommandTimeout;
}



Followup

Message
Date: 2009-07-02 15:00
Sender: Francisco Figueiredo jr.


Fixed in cvs.

Please give it a try and let us know if it worked for you.

Attached Files:

Changes:

No Changes Have Been Made to This Item

Powered By FusionForge