Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 1st, 2009, 04:43 PM
Registered User
 
Join Date: Sep 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default New to ASP.NET - can't connect to DB!

Hi folks,

For some reason, the following simple code will not produce any results although there are 2 rows in the database. Not even an error. I've tried like 30 different connectstrings. The IIS web server and the SQL Express SQL Server are both on the same PC. Could you please look at it and give me some ideas?

TIA, DanielInTenn

---code---

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Import Namespace="System.Data.OleDb" %>

<script runat="server">
sub Page_Load
Dim dbconn As OleDbConnection, sql As String, dbcomm As OleDbCommand, dbread As OleDbDataReader
dbconn = New OleDbConnection("Driver={SQL SERVER};Data Source=DANIEL-PC\SQLEXPRESS;Initial Catalog=Nicecars;UID=cars;PWD=mustang")
dbconn.Open()
sql = "select * from cars order by CaridNo "
dbcomm = New OleDbCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()
cars.DataSource = dbread
cars.DataBind()
dbread.Close()
dbconn.Close()
end sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Browse Automobiles</title>
</head>
<body>
<form id="carform" runat="server">
<asp:Repeater ID="cars" runat="server">

<HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>Year</th>
<th>New or Used</th>
<th>Make</th>
<th>Model</th>
<th>Mileage</th>
<th>Color</th>
<th>Details</th>
<th>Price ($)</th>
<th>Body Style</th>
</tr>
</HeaderTemplate>

<ItemTemplate>
<tr>
<td><%#Container.DataItem("Year").GetType%></td>
<td><%#Container.DataItem("Year")%></td>
<td><%#IIf(Container.DataItem("IsNew"), "New", "Used")%></td>
<td><%#Container.DataItem("Make")%></td>
<td><%#Container.DataItem("Model")%></td>
<td><%#Container.DataItem("Mileage")%></td>
<td><%#Container.DataItem("Color")%></td>
<td><%#Container.DataItem("Details")%></td>
<td><%#Format(Container.DataItem("Price"), "$###,###")%></td>
<td><%#Container.DataItem("BodyStyle")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>
 
Old September 1st, 2009, 05:13 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Can you please post message like these in a more general forum on ASP.NET, like this one: http://p2p.wrox.com/asp-net-3-5-basics-351/

The one you posted in right now is just for the book Beginning ASP.NET 3.5 in C# and VB.NET.

BTW: try creating a new page in Visual Studio and then copy in your code into that new page. This gives you a proper Page Directive as yours is messed up (did you copy it from a C# example?):

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

AutoEventFireUp is False in VB.NET requires you to add a Handles keyword for the event to handle. In your case it means that Page_Load is never called because you're not telling it to do so.Simply delete the entire attribute.

CodeFile: You're using in-line code so there is no code file.

Inherits: You're using in-line code so there is nothing to inherit from (other than the Page class). So, a better Page directive looks lke this:

<%@ Page Language="VB">

Then you'll see Page_Load gets called and you can work from there.


Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 2nd, 2009, 06:55 PM
Registered User
 
Join Date: Sep 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks, Imar

Thanks, Imar, everything works now in my first ASP.NET page (I've been a long time programmer of classic asp).

However, when trying to make this page the default web page (I've made it so in the IIS default page icon) it makes the web site unreachable. It runs fine when I run it from VS 2008... Is there a setting on the web site itself I have to make to allow ASP.NET applications to run?

TIA,

Daniel
 
Old September 3rd, 2009, 06:55 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Have you configured IIS correctly? Did you install IIS before or after .NET? In case you installed it after you installed .NET and Visual Studio, you need to run aspnet_regiis -i to register .NET with IIS.

Otherwise, you'll need to provide more information. What OS are you using? How did you configure IIS? Did you grant security permissions to the folder that contains the ASPX page and so on? What error message do you get exactly?
Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 3rd, 2009, 08:39 AM
Registered User
 
Join Date: Sep 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks for your response, my answers

My configuration:

Vista Ultimate 32 bit (on a dual-athlon 3gb HP box)
MS Visual Studio 08 SP1
IIS 7.0 (after I installed VS 08, I went into control panel and installed IIS that way)

I don't recall installing .NET separately, I suspect it is pre-installed in Vista? In any case, I went to the microsoft .net site and downloaded the latest .net updates.

I have run aspnet_regiis -i. No change. I get a "file not found" error regardless if I put the ASP default.aspx or the old default.htm on the website (which did work at some point). I'm afraid I've muddled IIS beyond my feeble ability to fix. Should I reinstall IIS?

As for security, I've verified that IIS_IUSR has READ and EXECUTE on the wwwroot directory structure.

I do appreciate your attention. I am going to buy your book today and spend all weekend working through it.

Regards,

Daniel
 
Old September 3rd, 2009, 08:43 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

The IIS_IUSR is not used by default for ASP.NET. Instead, it uses an account called Network Service which you need to give rights.

Visual Studio 2008 installs the .NET Framework for you, and VS 2008 SP1 upgrades the framework to SP1 as well.

If you look at the Handler Mappings section of your site in IIS, to what handler is the ASPX extension mapped?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Last edited by Imar; September 3rd, 2009 at 08:47 AM..
 
Old September 3rd, 2009, 09:10 AM
Registered User
 
Join Date: Sep 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default I just gave Network Service Rights

It did not have any (??). However, that did nothing to fix the web site (I gave the "Network Service" nearly full rights for wwwroot, everything except delete).

Would uninstalling/installing IIS do any good?

Thanks again,

Daniel
 
Old September 3rd, 2009, 09:18 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Or consider reinstalling the .NET Framework. It seems that IIS is not fully aware of ASP.NET. Do you have a category called ASP.NET in your IIS settings? With a bunch of items that start with .NET (Authorization, Compilation and so on)?

http://www.microsoft.com/downloads/d...displaylang=en

Also, make sure you checked the ASP.NET option when installing IIS. It's not selected by default so you may need to check it first.

What message did youget when you ran aspnet_regiis -i?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 3rd, 2009, 10:57 AM
Registered User
 
Join Date: Sep 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks again, one more question, lol

I reinstalled IIS and VS08sp1 - NO HELP!

I am going to reinstall the operating system so I can get a clean install: that seems to be the only way I am going to get out of this. I also have a PC I'm picking up from servicing that has never had VS or IIS installed, so I am going to install on that one and see if I have any luck.

Any recommendations on install order for IIS, SQL Server Express, and VS08 on a clean PC?

Thanks,

Daniel

p.s. I got a successful message when I ran aspnet_iis -i.
 
Old September 3rd, 2009, 11:07 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Daniel,

You have to install IIS first, then VS 2008 which should also install SQL Server.

You may want to try the Web Platform Installer: http://www.microsoft.com/web/downloads/platform.aspx It installs everything you need in one fell swoop. You may want to try it and see if that fixes your problems before you reinstall the OS.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to connect to Access db thru VB.NET? am_kuthus Visual Studio 2008 1 June 3rd, 2008 04:48 AM
Error trying to connect with ASP.NET 2.0 wayne62682 SQL Server 2005 1 July 14th, 2006 04:10 PM
cant connect to DB using ASP and ADO paulmcn MySQL 2 February 6th, 2006 07:09 AM
Connect to MSDE in with ASP.NET hoeknu Classic ASP Databases 1 February 4th, 2004 09:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.