Solved

Move website from iis6 to iis7 (There is no row at position 0. )

Posted on 2013-05-16
3
739 Views
Last Modified: 2013-08-12
Moved a website that uses ASP.Net/Ajax2.0.  The database is MS SQL 2008R2  There has not been any code changes.

The following code:

            custID = myDataSet.Tables.Item(0).Rows(0).Item("CustID")


Is causing the following error:
Server Error in '/' Application.
--------------------------------------------------------------------------------

There is no row at position 0.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:


Line 174:            Dim myAdapter As New SqlDataAdapter(command)
Line 175:            myAdapter.Fill(myDataSet)
Line 176:            custID = myDataSet.Tables.Item(0).Rows(0).Item("CustID")
Line 177:            connection.Close()
Line 178:        End Using
 

Source File: C:\inetpub\sorder\serviceorder.aspx.vb    Line: 176

Stack Trace:


[IndexOutOfRangeException: There is no row at position 0.]
   System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) +2545949
   System.Data.RBTree`1.get_Item(Int32 index) +16
   System.Data.DataRowCollection.get_Item(Int32 index) +16
   ServiceOrder.getCustomerID() in C:\inetpub\sorder\serviceorder.aspx.vb:176
   ServiceOrder.insertComputer() in C:\inetpub\sorder\serviceorder.aspx.vb:252
   ServiceOrder.btnSubmit_Click() in C:\inetpub\sorder\serviceorder.aspx.vb:360
   ServiceOrder._Lambda$__3(Object a0, EventArgs a1) in C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\7c866b57\59c1fa31\App_Web_xlgzmri2.2.vb:0
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

 --------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4984; ASP.NET Version:2.0.50727.4971

More Details:
Here is the code in context:

Private Function getCustomerID() As Boolean
        Using connection As New SqlConnection(cs)
            'Specify the SQL query
            Const sql As String = "SELECT CustID FROM Customer WHERE FName = @FName AND LName = @LName;"
            Dim command As New SqlCommand(sql, connection)
            Dim first As SqlParameter
            first = New SqlParameter()
            first.ParameterName = "@FName"
            first.DbType = Data.DbType.String
            first.Value = txtFname.Text
            Dim last As System.Data.SqlClient.SqlParameter
            last = New System.Data.SqlClient.SqlParameter()
            last.ParameterName = "@LName"
            last.DbType = Data.DbType.String
            last.Value = txtLname.Text
            command.Parameters.Add(first)
            command.Parameters.Add(last)
            'Get back a DataSet
            Dim myDataSet As New Data.DataSet
            'Create a SqlDataAdapter instance
            Dim myAdapter As New SqlDataAdapter(command)
            myAdapter.Fill(myDataSet)
            custID = myDataSet.Tables.Item(0).Rows(0).Item("CustID")
            connection.Close()
        End Using
        getCustomerID = True
    End Function

Here is the layout of the database:
      [CustID] [int] IDENTITY(1,1) NOT NULL,
      [LName] [varchar](25) NOT NULL,
      [FName] [varchar](25) NOT NULL,
      [Apartment] [varchar](35) NULL,
      [Street] [varchar](35) NOT NULL,
      [City] [varchar](25) NOT NULL,
      [State] [nchar](2) NOT NULL,
      [Zip] [nchar](5) NOT NULL,
      [WorkNo] [nchar](12) NULL,
      [HomeNo] [nchar](12) NULL,
      [CellNo] [nchar](12) NULL,
      [FaxNo] [nchar](12) NULL,
      [Email] [varchar](100) NULL,
      [HeardHow] [varchar](30) NOT NULL,
 CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED

Up to the point where we have to submit the form, the rpogram works fine.  Even the main menu.

Any thoughts?
0
Comment
Question by:computrex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39174373
Nothing to do with IIS. Your data has changed and myDataset.Tables has not rows.

I would change it to following

If myDataSet.Tables(0).Rows.Count > 0 Then
   custID = myDataSet.Tables(0).Rows(0).Item("CustID")
End If
0
 
LVL 5

Author Comment

by:computrex
ID: 39174400
There is almost 800 rows of data.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39174415
Matching the LName and FName? Obviously its not being populated in the dataset hence the error.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question