Daniel Sh.
Daniel Sh.

Reputation: 2074

ASPX works locally but not on server

I have uploaded a web project on the server.

While it was running smoothly on my local pc where the development was made, it's not running at all on the server. As far as I can read the error, theres' a problem with an empty DataSet (fetches data from a SQL db). Again, when running the aspx locally everything is ok. Another issue I see on the errorlog is it points to my local drive "D:..." Shouldn't it point to the server address?

Error.

There is no row at position 0.

Exception Details: System.IndexOutOfRangeException: There is no row at position 0.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[IndexOutOfRangeException: There is no row at position 0.]
   System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) +2474798
   System.Data.DataRowCollection.get_Item(Int32 index) +21
   WEB.Default.Page_Load(Object sender, EventArgs e) in D:\dev\Visual Studio\Temp\WEB\Default.aspx.cs:59
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.UI.Control.LoadRecursive() +71
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064

Any idea? I use the publish tool from VS2010 and it succesfully uploads in the server. But it's not working.

Another thing I don't get is, why the webpage sends this error if I have a try/catch in the page load. If there's an error, it sets a Label with a friendly message.

Thanks.

EDIT

Here's the page load code.

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                Session["FlagOpen"] = false;
                var windowsIdentity = WindowsIdentity.GetCurrent();
                if (windowsIdentity != null)
                {
                    var userName = windowsIdentity.Name;
                    userName = Regex.Replace(userName, ".*\\\\(.*)", "$1", RegexOptions.None);
                    var ds = _objUser.GetRanking(userName);
                    var ranking = ds.Tables[0].Rows[0][1].ToString();
                    _objPersona.Ranking = ranking;
                    _objPersona.UserName = userName;
                    _objPersona.RealName = ds.Tables[0].Rows[0][0].ToString();
                    Session["User"] = _objPersona;
                    LblUserName.Text = ds.Tables[0].Rows[0][0].ToString();
                    ds = _objUser.GetFAQ(userName);
                    var cant = ds.Tables[0].Rows.Count;                        
                }
                else
                {
                    BtnAbrirBandeja.Enabled = false;
                    LblUserName.Text = "Not allowed.";
                }
            }
        }
        catch (Exception)
        {
            LblWarnings.Text = "Error. Please contact sysadmin.";
            throw;
        }

    }

EDIT 2.

Page keeps working locally. But not on the server. It throws the original error pointing to a local folder (when it's already uploaded and running from the server). The DataSet being null is a consequence of the web not being able to communicate with the SQL server. Hence the error. Basically, it runs OK while debugging, but not on server.

Any ideas? Thanks.

Upvotes: 0

Views: 1942

Answers (3)

techBeginner
techBeginner

Reputation: 3850

May be when running on your local machine it was taking data from your local server and now its getting data from your server database engine..tables may be empty there or may be tables not exist there.. Check your dataset fetching method for any errors..your try catch might have hidden that error..

your another part of question:

It throws that exception because your catch block has a 'throw' statement, which will just through the same error catched by the catch block with all the inner exception details..

Note: if you write catch(Exception ex) {throw ex;}

inner exception details would be lost...

Upvotes: 1

JonH
JonH

Reputation: 33183

You need to test your dataset for null before you try to access an element from the dataset, hence the error message:

if (ds!=null)
 { 
  //continue and access the dataset
 }
else
 {
  //you didn't get any data or ds is simply null (result set is null)
 }

You are also misusing the var keyword, you don't need to use var for simple types like strings and datasets.

Upvotes: 1

PhonicUK
PhonicUK

Reputation: 13864

For whatever reason your data is inaccessible or doesn't exist:

[IndexOutOfRangeException: There is no row at position 0.]

var ranking = ds.Tables[0].Rows[0][1].ToString();

You need to be checking ds.Tables.length (or count as it may be) before performing that line.

Upvotes: 1

Related Questions