c# - "Cannot find Table[0]" - Only in production? -


Some code on our production server is suddenly giving us some trouble. Production has not been changed in nearly one year, and I have confirmed There is no change in the database.

If I run the same code on my machine (i.e. source control!), Then I do not get the error that appears in the production and everything works fine. I will post the code below, but there will be some more to run.

Correct me if I am wrong, but if there is no table [0] , that means that my query is not returning any data, even then, SQL By running a single question directly through the management studio, I get the data that I need.

var ds = GetData (queryString); If (Dtsibles.Count> 0) {var ddlDataSet = GetAdds (); } Private listing & lt; TAdd & gt; GetAdds () {var ds = GetData (queryString); Var aList = new tAdd [ds.Tables [0] .Rows.Count]; // This is where error hits // other stuff ...} private dataset GetData (string query string) {var connectionString = ConfigurationManager.ConnectionStrings ["constring"] ConnectionString. Var ds = new dataset (); Try {var connection = new SqlConnection (connectionString); Var Adapter = New SqlDataAdapter (queryString, Connection); Adapter.fill (ds); } Hold (exception before) {ErrorPanel.Visible = true; ErrorPanel.Enabled = true; SearchPanel.Enabled = false; Constant String Notification Amel = "Mail: EmailGu @ Email" "ErrorAlertLabel.Text =" One Mistaken. "+" Please Contact People "; ErrorAlertLabel.Visible = true; ErrorMessageLiteral.Text =" & lt; Br / & gt; "+" & lt; Br / & gt; "+" Message: "+ East + Message +" & lt; Br / & gt; "+" StackTrace: "+ East StackTrace +" & lt; Br / & gt; "+" Internal Exception: "+ ex.InnerException +" & lt; Br /> "+" Full Detelles: "+ Pre +" & lt; Br /> "ErrorMessageLiteral.Visible = true;} return DS;}

I can try to publish the same version again, but who knows If he needs more information then please let me know and thank you.

Actual error text: "System.IndexOfRangeException: Table 0 can not find "

I think you still have a flaw in dealing with your error. Gone has come.

In GetData , you have exception this happens and the UI is visible to set up a group of elements And populates them with information, but you continue to do not stop the process from continuing GetData just hold blocks , And a blank DataSet . GetAdds Unaware of the fact that there was an error, he tried to reach the table in DataSet That does not exist, and throws an exception to the other that is not handled by your code, but instead is handled by ASP.NET, which throws all your error information and just a normal The error page shows.

I use this kind of detailed error management low-level method, but more global error handling. Since you do not add any meaningful information to the exception, then I make it bubble and keep it at the application level.

If you want to add more information to a lower-level exception, then with an exception new exception, and the new exception InnerException Assign the original exception.


Comments