Link to home
Start Free TrialLog in
Avatar of BWA IT
BWA IT

asked on

Visual Basic code not firing when I launch ASP.Net Site

Hi, I deployed an asp.net website with vb code behind to a local directory. I then copied it to a cloud server with IIS and added it to IIS. I can run the website from the browser. The first page is just a listbox with a list of ssrs reports that retrieved from code in the page_load function. However when run the website from the browser the listbox shows but it is empty. This suggests that the vb code behind is not running. It works fine when I run it through visual studio on my local machine. Any help or suggestions would be greatly appreciated.

Thanks
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

can u post the code behind where u populate the listbox?
Avatar of BWA IT
BWA IT

ASKER

Here's the code for page_load, thanks:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ''LOAD REPORTS LIST
        Dim CommandText As String
        Dim reader As SqlDataReader
        Dim selectCommand As SqlCommand
        Dim connection As SqlConnection = New SqlConnection("Data Source=cloud-sql-01;Initial Catalog=ReportServer;Integrated Security=True")
        If (IsPostBack = False) Then
            ''Populate Outstanding Orders Label
            Try
                CommandText = "select Name, Path from catalog where type not in (1,5) " &
                               "and Path like '%BWA Reports/Terms and Conditions Documents/%' " &
                                " and Name not like '%sub%'" &
                                   " order by path, Name"


                connection.Open()
                selectCommand = New SqlCommand(CommandText, connection)

                ' run the query and obtain a reader to get the results


                selectCommand.Connection = connection

                reader = selectCommand.ExecuteReader


                While reader.Read()
                    If reader.Item(0).ToString <> "" Then
                        lbReports.Items.Add(reader.Item(0))
                    End If
                End While



                selectCommand.Dispose()
                connection.Close()
                reader.Close()

            Catch ex As Exception
                'msgBox(ex.Message)
            End Try


            ''Hide Dividers
            divinitialp.Visible = False
            divInvoicep.Visible = False
            divlist.Visible = False
            divTermsOptions.Visible = False
            divorderackparameters.Visible = False
            divLineno.Visible = False
        End If
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ''LOAD REPORTS LIST
        Dim CommandText As String
        Dim reader As SqlDataReader
        Dim selectCommand As SqlCommand
        Dim connection As SqlConnection = New SqlConnection("Data Source=cloud-sql-01;Initial Catalog=ReportServer;Integrated Security=True")
        If (IsPostBack = False) Then
            ''Populate Outstanding Orders Label
            Try
                CommandText = "select Name, Path from catalog where type not in (1,5) " &
                               "and Path like '%BWA Reports/Terms and Conditions Documents/%' " &
                                " and Name not like '%sub%'" &
                                   " order by path, Name"


                connection.Open()
                selectCommand = New SqlCommand(CommandText, connection)

                ' run the query and obtain a reader to get the results


                selectCommand.Connection = connection

                reader = selectCommand.ExecuteReader


                While reader.Read()
                    If reader.Item(0).ToString <> "" Then
                        lbReports.Items.Add(reader.Item(0))
                    End If
                End While



                selectCommand.Dispose()
                connection.Close()
                reader.Close()

            Catch ex As Exception
                'msgBox(ex.Message)
            End Try


            ''Hide Dividers
            divinitialp.Visible = False
            divInvoicep.Visible = False
            divlist.Visible = False
            divTermsOptions.Visible = False
            divorderackparameters.Visible = False
            divLineno.Visible = False
        End If

Open in new window

put break point on line 28, do u get inside the reader code?
Avatar of BWA IT

ASKER

Do you mean put a break point in Visual Studio? If so yes it reads fine when debugging in visual studio. If you mean put a break point when I run the website sorry i'm not sure how, this is the first asp.net website I have deployed.

Thanks
put a break point on line 28 and attach to process w3wp.exe, then run the web site, u suppose to hit the breakpoint then.
This could also mean that the code is probably running but not retrieving anything to add to list. Try following

Dim Count As Integer = 0
While reader.Read()
                    If reader.Item(0).ToString <> "" Then
                        Count += 1
                        lbReports.Items.Add(reader.Item(0))
                    End If
End While
lbReports.Items.Add("Total Reports: " & Count)
Avatar of BWA IT

ASKER

I don't have visual studio on the website server, can I still attach w3wp.exe
does it happen when u run locally (while in development mode) or only on production?
Avatar of BWA IT

ASKER

only on production, works fine when i run in visual studio
do u get any exceptions?
Avatar of BWA IT

ASKER

no don't get any exceptions. Thanks
so the problem is that the reader yields no data.
if u have access to production DB, u should try first run the query against it.
so take this query:
select Name, Path from catalog where type not in (1,5)  and Path like '%BWA Reports/Terms and Conditions Documents/%'  and Name not like '%sub%' order by path, Name

Open in new window

do u get any results?
Avatar of BWA IT

ASKER

Yes the query works fine, as I say when I run in visual studio it loads perfectly which is why i am so confused as to why the deployed site doesn't work. Could it be a permissions thing between the database and the server holding the website?
no, cause u would have get exception if that was the case.
when u run in visual studio, are you positive u query the production DB?
same connection string??
Avatar of BWA IT

ASKER

Yes exactly the same, I have just tried adding a label to the home page in the page_load code have added Label1.Text = "Hello". This works fine so this at least shows that the vb code behind is running. So, as you are implying, it must be something to do with the connection to the db. The query works in in visual studio and it works when I run it in sql management studio so not sure what ti could be...
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BWA IT

ASKER

Hi, I tried the code below and value is 0 in visual studio even though the listbox populates:

hile reader.Read()
                    If reader.Item(0).ToString <> "" Then
                        lbReports.Items.Add(reader.Item(0))
                    End If
                End While

                Dim dt As New DataTable()
                dt.Load(reader)
                File.WriteAllText("C:\Site.log", dt.Rows.Count.ToString)

I tried the line you suggested: lbReports.Items.AddRange(dt.Select(Function(row) row(0).ToString).ToArray) but it didnt compile. "Lambda expression cannot be converted to string")

Thanks