Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #21 (permalink)  
Old January 29th, 2012, 04:38 PM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default IIS problems

I am sorry I am running both SQL Express and SQL Server 2008 the developer's edition. But I have both SQL Express and regular SQL running under the Enterprise Management Studio. I got my terms mixed up with Oracle. Not Enterprise Manager but SQL Server Management Studio. My bad.

Imar said:
This is confusing. Are you using Express or the full commercial version? And which version of Express? What did @@version tell you?

It says version: Microsoft SQL Server 2008 (SP2) - 10.0.4064.0 (X64) Feb 25 2011 13:56:11 Copyright (c) 1988-2008 Microsoft Corporation Express Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)
Reply With Quote
  #22 (permalink)  
Old January 29th, 2012, 07:33 PM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default IIS Failure

Code:
I created a very, very simple webpage, with no code behind. It runs fine in Cassini and it doesn't run when it is runs under an IIS virtual directory. Same error message as before:

 <%@ Page Language="C#" %>
<%@ Import Namespace = "System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  protected void Page_Load(object sender, EventArgs e)
  {
    //  Create a new connection object
    SqlConnection conn = new SqlConnection(
        "Server=localhost\\SqlExpress;Database=Employees;" +
        "Integrated Security=True");
    // Create a new command object
    SqlCommand comm = new SqlCommand(
      "SELECT EmployeeID, Name FROM Employees", conn);
    // Open connection
    conn.Open();
    // Execute the command
    SqlDataReader reader = comm.ExecuteReader();
    // Read and display the data
    while (reader.Read())
    {
      employeesLabel.Text += reader["Name"] + "<br />";
    }
    // Close the reader and the connection
    reader.Close();
    conn.Close();
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head runat="server">
    <title>Using ADO.NET</title>
  </head>
  <body>
    <form id="form1" runat="server">
      <div>
        <asp:Label ID="employeesLabel" runat="server" />
      </div>
    </form>
  </body>
</html>

I don't know, maybe you can take this snippet and see if you can reproduce on your local machine at home or something. I am totally lost on this issue.
Reply With Quote
  #23 (permalink)  
Old January 29th, 2012, 10:19 PM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default IIS Failure

Just so you know, I put the Planet Wrox.MDF file back under the App_data folder in the server explorer in Visual Studio 2010 changed the connection string back to the way it originally was and it runs just fine under IIS control. But if try to change the connection string to try to go to the instance that runs under SQL Server 2008, it croaks out again. Go figure!!! I am a total loss for words and I don't know what can be done to fix the problem, other than to run all of my ASP.NET 4.0 apps with the .mdf file running under the App_data folder in Visual Studio 2010. Maybe you might have some ideas as to what is going on here, but as for me I have no clue. To tell you the truth I am beginning to think that there are actual gremlins inside the machine that are mucking things up deliberately :-) or ;-) is better face to use.

Thanks again.

Vbboyd
Reply With Quote
  #24 (permalink)  
Old January 29th, 2012, 10:22 PM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default IIS Failure

PS I wanted to add that I am not able to connect to SQL server except in only the Windows Authentication mode. If you want to go use SQL Authentication to connect to SQL Server, well then FORGET ABOUT IT!!!!
Like I say there must be MicroGremlins in the computer system playing nasty tricks on me.

Thanks once again
vbboyd

PSS
If you have any ideas about what might be happening here, I would be personally very grateful and appreciative.
Reply With Quote
  #25 (permalink)  
Old January 30th, 2012, 04:33 AM
Imar's Avatar
Wrox Author
Points: 71,561, Level: 100
Points: 71,561, Level: 100 Points: 71,561, Level: 100 Points: 71,561, Level: 100
Activity: 40%
Activity: 40% Activity: 40% Activity: 40%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,002
Thanks: 79
Thanked 1,574 Times in 1,551 Posts
Default

Quote:
I created a very, very simple webpage, with no code behind. It runs fine in Cassini and it doesn't run when it is runs under an IIS virtual directory.
Hi there,

All of this makes perfect sense and comes down to what I have been saying for the past couple of posts: it's a security permission issue. Taking your code and run it on my machine wouldn't help. The code is probably fine, it's the security between your IIS account and SQL Server that is the problem.

Again, Chapter 19 and Appendix B provide all the answer as they a) explain how security works, b) how to figure out under which account your site runs and c) how to grant that account permissions to the database.

You seem to be overlooking important parts in these chapters, so here's a quick run-down.
  1. When you run under Cassini, the web site runs under *your* user account. Since this user account probably has Admin rights everything works fine.
  2. When you run your site under IIS, it runs under some system account. Which account that is depends. On Windows 7, the default is IIS AppPool\NameOfYourApplicationPool.
  3. This system account needs permissions to access your SQL Server and your database. For that, you need a login (SQL Server wide) and a user (for your database).
Here's how to make this work:
  1. Start the IIS Manager
  2. Locate your Application Pool (called PlanetWrox judging by one of your earlier posts) under the Application Pools node.
  3. Double-click it and make sure it uses .NET 4 and Integrated pipeline mode. Click OK.
  4. Right-click the pool and choose Advanced Settings. Under Identity, make sure ApplicationPoolIdentity is selected.
  5. Switch to the Sites node of the IIS Manager and locate your site
  6. Right-click it and choose Manage Web Site | Advanced Settings
  7. Under Application Pool make sure you select the pool you configured in the previous steps.
  8. Just to be sure, restart IIS (click the name of your machine in IIS Manager and then click Restart)
  9. Go into SQL Server (Express, as that's what you seem to be using) using Management Studio
  10. Expand Security | Logins for the *entire server*.
  11. Create a new login for IIS AppPool\PlanetWrox. As the Login name enter IIS AppPool\PlanetWrox and click OK
  12. Go into your database, expand Security | Users and create a new user by entering IIS AppPool\PlanetWrox twice. Assign this user to the data reader and data writer *roles* (not schemas)
  13. Open the web.config and change localhost\SqlExpress to .\SqlExpress. Both should be the same but I have seen situations where the former doesn't work.
  14. Try again.
You'll find detailed steps for the SQL Server part on page 768 and further. The IIS part is explained on page 715 and further.

Quote:
If you want to go use SQL Authentication to connect to SQL Server, well then FORGET ABOUT IT!!!!
Not forget about it; but configure it. By default SQL Server doesn't allow SQL Server Authentication. To change that, log in to SQL Server Management Studio, right-click your server and choose Properties. On the "Security" page you can switch modes. However, I recommend not to do this unless you have the need. Using Integrated Security is safer and usually easier to manage.

If all this keeps failing, please work your way completely through Chapter 19 and Appendix B. All of this information is in there, along with detailed steps and an explanation of why you need to do what and where.

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!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
iis.msc equivalent in IIS for Win XP Pro? RealDHelix Classic ASP Basics 14 March 18th, 2007 08:28 PM
Help in Assertion failure abdelkader Visual C++ 0 December 30th, 2003 09:43 AM
CreateObject error on IIS 4 but not IIS 5 timtom Classic ASP XML 1 December 5th, 2003 12:26 PM
Catastrophic failure cyberbhaskar Classic ASP Databases 0 September 16th, 2003 12:19 AM



All times are GMT -4. The time now is 02:50 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.