Solved

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

Posted on 2013-06-27
17
342 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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