Solved

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

Posted on 2013-06-27
17
343 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

713 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