.NET Application Problem

Hi,

I'm having trouble with my .net application...

I have a file that has a datagrid and the code is as follows:
Code:
<asp:datagrid id="MyDataGrid" runat="server" OnDeleteCommand="MyDataGrid_Delete" DataKeyField="ID" HeaderStyle-BackColor="#CCCCCC"
				Font-Size="10pt" Font-Name="Arial" CellSpacing="1" CellPadding="3" ShowFooter="false" Width="700">
				<Columns>
					<asp:ButtonColumn Text="Delete News Item" CommandName="Delete" />
				</Columns>
			</asp:datagrid>

I have also a backend c# file which contains the implementation:

Code:
public void Page_Load(Object sender, EventArgs e)
		{
			myConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["DBConnectionString"]);

			if (!IsPostBack)
				BindGrid();
		}

		public void MyDataGrid_Delete(Object sender, DataGridCommandEventArgs e)
		{
			String deleteCmd = "DELETE from News where ID = @Id";

			SqlCommand myCommand = new SqlCommand(deleteCmd, myConnection);
			myCommand.Parameters.Add(new SqlParameter("@Id", SqlDbType.NVarChar, 11));
			myCommand.Parameters["@Id"].Value = MyDataGrid.DataKeys[(int)e.Item.ItemIndex];

			myCommand.Connection.Open();

			try
			{
				myCommand.ExecuteNonQuery();
				Message.Text = "<b>Record Deleted</b><br>" + deleteCmd;
			}
			catch (SqlException)
			{
				Message.Text = "ERROR: Could not delete record";
			}

			myCommand.Connection.Close();

			BindGrid();
		}

		public void BindGrid()
		{
			SqlDataAdapter myCommand = new SqlDataAdapter("select * from News", myConnection);

			DataSet ds = new DataSet();
			myCommand.Fill(ds, "News");

			MyDataGrid.DataSource=ds.Tables["News"].DefaultView;
			MyDataGrid.DataBind();
		}

It works absolutely fine on my local server here but I am not sure why it isn't working on the JodoHost server... I get an unspecified error when doing that.... I just thought I would post and see what's wrong.... Can you please help?

Thanks!
 
Now I get the unspecified runtime error message throughout the application itself, is there any configuration I need to do to match the server settings?


Here is the error:

Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
 
Please turn off custom errors so we can see the actual error. You might also want to verify the field types between what you have at home and what's at JodoHost -- int should be int, etc. An error will occur if you key field is of the wrong type than the stored procedure is expecting.
-Dave
 
Alright, well I already have customErrors mode set to off in my web.config file but it isnt recognizing that... It still shows up with that error...

I have checked and re-checked that all the database types are the same, int varchar, etc as my localhost database...

My table also has a identity which is the ID itself, the table is named news....
 
I keep turning the customErrors mode off, but it still displays that error... I am not sure as to why it is doing that... I cleared my cache and that is not the case....
 
Put a try-catch block around the code and catch the Exception typed error, then write out the Exception.Description yourself. See if you can find out what it says and post your findings....
-Dave
 
Hi WineIsGood,

I appreciate your help... I have managed to get the customErrors mode to be off and I did see the error, I have since fixed that error, but whenever I execute the above, I just get a blank page...

I checked the database and it does have rows in it....

Everything above is the same....

Thanks for your help...
 
DigitalSolution said:
I appreciate your help... I have managed to get the customErrors mode to be off and I did see the error, I have since fixed that error, but whenever I execute the above, I just get a blank page...

DigitalSolution,

Here's a thought...
The code you posted is expecting a datatable named News, and in your post you said its name is news. Perhaps its a case problem. Is the table named news or News?

riley
 
DigitalSolution said:
The table is named News, Sorry about the confusion....

Well, I was grasping at straws anyway. It probably isn't a problem of case, as your code is consistent in the use of News (initial cap). This is a strange one; your code looks ok to me. I'll keep thinking about it...

By the way, I assume you mean it comes up empty on its initial load. Is that right? Or does it load ok until you do a delete?

riley
 
The page doesnt dataBind to the data grid... It comes up blank... When I view source, I see the application executed but no content... I am still trying to figure it out....


Thanks for your help Riley... Appreciate it
 
Are you pressing F5 (reload) to test the page once you make a change, recompile, and re-upload? If so, it's executing a postback and therefore your Page_Load() won't run the data bind code... just something to think about -- lots of my programmers make the same mistake, only to take a lunch break, come back, open IE, and it works to their surprise with no change!
Also -- did you place code into your Try-Catch exception block? If it fails, it'll end up there, but with no code you'll see a blank page. At least response.write("Oops!") and then get deeper by printing the actual error. Lastly, try placing code everywhere to see where it's going... response.write("I'm in page_load"), response.write("I'm in data bind"), etc., etc...
-Dave
 
WineIsGood said:
Also -- did you place code into your Try-Catch exception block? If it fails, it'll end up there, but with no code you'll see a blank page. At least response.write("Oops!") and then get deeper by printing the actual error. Lastly, try placing code everywhere to see where it's going... response.write("I'm in page_load"), response.write("I'm in data bind"), etc., etc...
-Dave

As always, WineIsGood has some great suggestions. It would also be interesting to temporarily modify your bindgrid function to update message.text with the rows.count propery, just to see if your datatable has any rows. That would help you isolate your problem between data-access and grid-binding. If the rows.count is 0, your problem rests somewhere in data-access. Otherwise, it's a binding problem with the grid.

riley
 
Hey, that's a good idea too -- that would cut your bug-search in half real quick. If it's a data error, trying running the SQL code in query analyzer to see if you get any rows back. In fact, try using SQL Profiler to inspect the actual command sent to the server... it may not be what you think it is! If it's a binding problem, try illiminating all columns except for the primary key and add from there until it fails.
-Dave

riley said:
As always, WineIsGood has some great suggestions. It would also be interesting to temporarily modify your bindgrid function to update message.text with the rows.count propery, just to see if your datatable has any rows. That would help you isolate your problem between data-access and grid-binding. If the rows.count is 0, your problem rests somewhere in data-access. Otherwise, it's a binding problem with the grid.

riley
 
Thanks a lot for the great tips guys....

I'll go ahead and debug the problem as soon as I have some time on my hands....

Again thanks for those great tips...

-Nirav
 
Back
Top