Solved

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

Posted on 2013-06-27
17
336 Views
Last Modified: 2013-06-28
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
0
Comment
Question by:BWA IT
  • 8
  • 8
17 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39280518
can u post the code behind where u populate the listbox?
0
 

Author Comment

by:BWA IT
ID: 39280538
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
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39280560
 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?
0
 

Author Comment

by:BWA IT
ID: 39280572
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
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39280575
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.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39280748
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)
0
 

Author Comment

by:BWA IT
ID: 39280787
I don't have visual studio on the website server, can I still attach w3wp.exe
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39280793
does it happen when u run locally (while in development mode) or only on production?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:BWA IT
ID: 39280893
only on production, works fine when i run in visual studio
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39280909
do u get any exceptions?
0
 

Author Comment

by:BWA IT
ID: 39281002
no don't get any exceptions. Thanks
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39281045
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?
0
 

Author Comment

by:BWA IT
ID: 39281051
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?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39281087
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??
0
 

Author Comment

by:BWA IT
ID: 39281138
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...
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39281219
put some logging code inside page_load.
my suspect is that IsPostBack equals true for some reason, or  you get empty string, which u check before add to lbReports (line 29).
To eliminate those assumptions write to some log file before executing the query.
and also log the count of dt.Rows.
also change lines 28 to 32 with this code:
DataTable dt = new DataTable()
dt.Load(reader)
File.WriteAllText("site.log", dt.Rows.Count.ToString)
lbReports.Items.AddRange(dt.Rows.Select(Fuction(row) row(0).ToString).ToArray)

Open in new window

0
 

Author Comment

by:BWA IT
ID: 39283671
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
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now