Description of Problem:
I have a function that gets called as a result of clicking a log in button (OnClick Event). If i put in an invalid password, the first time it gives me an appropriate exception ('invalid login') the second time the error is more indicative of a bug ('reference not set to instance of an object' or similar wording).
Steps to reproduce the problem:
1. Create a screen which prompts for username/password
2. Place a login button on the screen, and set the callback function to create a new sqlconnection(connection_string), then have it call Open() on that connection.
3. Click login more than once with an invalid password.
Here's some sample code for the onclick event:
protected void LoginClick (object sender, System.EventArgs e)
SQLConn = "Data Source=robwilkenssql.db.6210828.hostedresource.com;Initial Catalog=robwilkenssql;User ID=" + UserText.Text + ";Password=" + PassText.Text + ";MultipleActiveResultSets=True;";
MyConnection = new SqlConnection(SQLConn);
MainMenuDlg Menu=new MainMenuDlg();//this only gets created if login succesful due to exceptions being raised on failure...
................. code removed from this point to exception handling
catch (Exception ex)
ShowMessage("Error logging into Database: "+ex.Message);
From Open: Exception that says (on 2nd attempt): Object reference not set to an instance of an object
From Open: Exception that says (on 2nd attempt): login failed for user 'username'
How often does this happen?
Every time, as long as it's the 2nd attempt (or later).
I have submitted a patch for this via github. I did not generate unit tests for it, and wasn't honestly sure how to start on that. It basically was a problem in Mono.Data.Tds.Protocol.TdsConnectionPool (which is called from SqlConnection.Open()) -- There's a condition in there where it would have to 'retry' (which happens on subsequent attempts if there is a dead connection in the pool), and before it went to the retry point it needed to reset 'result=null' which it wasn't doing, because at the top of the retry point the first thing it does is check "while (result == null)" to enter the loop, and the loop was being bypassed because it was never null on retries. It needs to be null to find a new result which was the point of the retry in the first place.
I did generate a unit test for it now, and that is available in the pull request on github.
Thanks for the patch!