Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Special Edition by Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muhammad, Srinivasa Sivakumar; ISBN: 9780470041789
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 7th, 2007, 05:16 PM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 11:

Chapter 11 Listing 11-17.
I have used the code exactly as described (changed the connection string) but an error persists:

-------
Unable to open the physical file "C:\SQL Server 2000 Sample Databases\NORTHWND.MDF". Operating system error 5: "5(Access is denied.)".
An attempt to attach an auto-named database for file C:\SQL Server 2000 Sample Databases\NORTHWND.MDF failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
-------

I have searched all over the net and I do not have an SQLEXPRESS directory.

What do I need to do to get this GridView to work?

Thank you,

Kiley
  #2 (permalink)  
Old March 7th, 2007, 06:49 PM
Authorized User
Points: 176, Level: 3
Points: 176, Level: 3 Points: 176, Level: 3 Points: 176, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Kiley!
Let me Ask you a Question.
Does your GRIDVIEW Control anables you to view the Northwind database (tables) at all? Does any of your Controls, Like SqlDataSource controls CAN retrieve any Data from your SqlServer 2000? at all?
What Server you using? 2000/2005/or the Express one?
Seems like this Listing Must work with the sequence, with the Listing
11-15,11-16- and finally the 11-17.
...Of course you can simply Copy/Paste this code Below.
..What do you mean by can't find SQEXPRESS? directory?
You get an error from SQl 2000 server Right?
There's no SQLEXPRESS Directory, If you simply have a single SQl2000server installed on your PC :)..???
AnyWay Please provide More Info about what Sql Server You Using.
..BE more specific!
... If you cannot retrieve ANY data at all from your Sql Server(Specifically from the NorthWind database) try to REINSTALL the NorthWind data base from the beginning.


This code Works Fine Under SqlServer2005
I have checked it up a minute ago.
works fine.

Listing 11-17
/************************************************
<%@ Page Language="C#" %>

<!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 GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        string oldExpression = GridView1.SortExpression;
        string newExpression = e.SortExpression;

        if (oldExpression.IndexOf(newExpression) < 0)
        {
            if (oldExpression.Length > 0)
                e.SortExpression = newExpression + "," + oldExpression;
            else
                e.SortExpression = newExpression;
        }
        else
        {
            e.SortExpression = oldExpression;
        }
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Listing11-17</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" Runat="server" DataSourceID="SqlDataSource1"
             DataKeyNames="CustomerID" AutoGenerateColumns="False"
             AllowSorting="True" OnSorting="GridView1_Sorting">
            <Columns>
                <asp:BoundField ReadOnly="True" HeaderText="CustomerID"
                     DataField="CustomerID"
                     SortExpression="CustomerID"></asp:BoundField>
                <asp:BoundField HeaderText="CompanyName" DataField="CompanyName"
                     SortExpression="CompanyName"></asp:BoundField>
                <asp:BoundField HeaderText="ContactName" DataField="ContactName"
                     SortExpression="ContactName"></asp:BoundField>
                <asp:BoundField HeaderText="ContactTitle" DataField="ContactTitle"
                     SortExpression="ContactTitle"></asp:BoundField>
                <asp:BoundField HeaderText="Address" DataField="Address"
                     SortExpression="Address"></asp:BoundField>
                <asp:BoundField HeaderText="City" DataField="City"
                     SortExpression="City"></asp:BoundField>
                <asp:BoundField HeaderText="Region" DataField="Region"
                     SortExpression="Region"></asp:BoundField>
                <asp:BoundField HeaderText="PostalCode" DataField="PostalCode"
                     SortExpression="PostalCode"></asp:BoundField>
                <asp:BoundField HeaderText="Country" DataField="Country"
                     SortExpression="Country"></asp:BoundField>
                <asp:BoundField HeaderText="Phone" DataField="Phone"
                     SortExpression="Phone"></asp:BoundField>
                <asp:BoundField HeaderText="Fax" DataField="Fax"
                     SortExpression="Fax"></asp:BoundField>
            </Columns>
        </asp:GridView>

        <asp:SqlDataSource ID="SqlDataSource1" Runat="server"
            SelectCommand="SELECT * FROM [Customers]"
            ConnectionString="<%$ ConnectionStrings:NorthWindConnectionString %>"
            DataSourceMode ="DataSet"
            ConflictDetection ="CompareAllValues" EnableCaching="True"
            CacheKeyDependency ="MyKey" CacheDuration="Infinite">
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>

I Still don't know my self what is Cache Dependency, CacheKeyDependency ="MyKey"
Since this named Mykey I'm not sure, yep maybe I'm wrong but you can remove this one, atleast it worked fine for me.
I'm still not sure but Maybe-Maybe this cause a problem that you have.
But I also think that you better first check your Sql server, if it's allows you to retrieve ANY data at all.
Tomorrow I'll try to run this code using Sql200Server and we'll see what we got.

Web.Config Your connection string Remember
/********************************

<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in
    machine.config.comments usually located in
    \Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
    <appSettings/>
    <connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data Source=MACHINEKEY;Initial Catalog=Northwind;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
    <system.web>
        <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
        <compilation debug="true"/>
        <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
        <authentication mode="Windows"/>
        <!--
            The <customErrors> section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
    </system.web>
</configuration>

...try to open you WEbBrowser and copy this to the AddressBox:
"C:\SQL Server 2000 Sample Databases Hit the Enter button

This will open a Window. Simply Look for this File: NORTWND.MDF Maybe it's Gone!?
  #3 (permalink)  
Old March 7th, 2007, 07:35 PM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I have cut/pasted the above code and get an error. Before I show that, my web.config file has this line which is very different from yours:

<add name="NORTHWNDConnectionString" connectionString="Data Source=GALACTICA\sqlexpress;User Instance=True;AttachDbFilename=&quot;C:\SQL Server 2000 Sample Databases\NORTHWND.MDF&quot;;Integrated Security=True" providerName="System.Data.SqlClient" />

Let me see if I can answer all the q's.

Visual Studio 2005
SQL Server 2005 Express
The database (NORTHWND.MDF) is at C:\SQL Server 2000 Sample Databases\NORTHWND.MDF

The error message is:
CREATE DATABASE permission denied in database 'master'.
An attempt to attach an auto-named database for file C:\SQL Server 2000 Sample Databases\NORTHWND.MDF failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

"What do you mean by can't find SQEXPRESS": there are loads of sites saying to delete a SQLEXPRESS directory, I haven't got one.

The database is there but .aspx error reads says:

CREATE DATABASE permission denied in database 'master'.
An attempt to attach an auto-named database for file C:\SQL Server 2000 Sample Databases\NORTHWND.MDF failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

I have been on this all day, your help is greatly appreciated.

Kiley



  #4 (permalink)  
Old March 7th, 2007, 07:42 PM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I just deleted all files in the web directory to start again. I recreated the default page and things were looking good until i rendered the page:

(Yes, Galactica is the name of my computer) ;)

Cannot open database "Northwind" requested by the login. The login failed.
Login failed for user 'GALACTICA\ASPNET'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Cannot open database "Northwind" requested by the login. The login failed.
Login failed for user 'GALACTICA\ASPNET'.

  #5 (permalink)  
Old March 7th, 2007, 07:57 PM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Default.aspx:


<%@ 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">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <asp:SqlDataSource
                ID="SqlDataSource1"
                runat="server"
                ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                SelectCommand="SELECT * FROM [Customers]">
            </asp:SqlDataSource>

    </div>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"
                DataSourceID="SqlDataSource1">
                <Columns>
                    <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
                    <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
                    <asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />
                    <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" SortExpression="ContactTitle" />
                    <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
                    <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                    <asp:BoundField DataField="Region" HeaderText="Region" SortExpression="Region" />
                    <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />
                    <asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
                    <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
                    <asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
                </Columns>
            </asp:GridView>
    </form>
</body>
</html>

web.config:
<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in
    machine.config.comments usually located in
    \Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
    <appSettings/>
    <connectionStrings>
        <add name="NorthwindConnectionString"
                    connectionString="Data Source=GALACTICA\sqlexpress;Initial Catalog=Northwind;Integrated Security=True"
          providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.web>
        <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
        <compilation debug="false" />
        <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
        <authentication mode="Windows" />
        <!--
            The <customErrors> section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
    </system.web>
</configuration>

This should just work but here is the error message:


Server Error in '/aspTest' Application.
--------------------------------------------------------------------------------

Cannot open database "Northwind" requested by the login. The login failed.
Login failed for user 'GALACTICA\ASPNET'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Cannot open database "Northwind" requested by the login. The login failed.
Login failed for user 'GALACTICA\ASPNET'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: ...

Is it just me???



  #6 (permalink)  
Old March 7th, 2007, 11:26 PM
Authorized User
Points: 176, Level: 3
Points: 176, Level: 3 Points: 176, Level: 3 Points: 176, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Kiley!
.. The truth is , as far as I remember I had this truble :)
But I really don't remember how I fixed this :) :(
..I remember that I Made a few changes in the SqlExpress2005Server by using SqlServerManagment Studio Express.
Second I Do know that the Main Answer is located somewhere in the
aspnet_regsql.exe
By typing this in VISUALSTUDIO2005 CommandPromt you will be able to set up this:
This Wizard creates or configures SQLDataBase that stores information
for ASP.NET applicationServices(membership,profiles,role managment,personalization and Sql Web Event Provider).
To configure the DataBase for these features individually, or for additionall features such as session state or SQL cache dependency, run aspnet_regsql.exe at the command line For help with the command line Options type: aspnet_regsql.exe -?

********************************************

Ok Open the VISUALSTUDIO2005 CommandPromt NOT the Regular Windows Command prompt!
Type cd.. hit enter and again cd.. hit enter untill you get this.
C:\>

so now type this
C:\>aspnet_regsql.exe -W hit Enter button

You will receive ThisWizardWindow...Follow the Image Instructions.
You will probably type aspnet_regsql.exe -W to get to the wizard window, In my case I type simple: aspnet_regsql.exe without W
Cause I have a SqlSErver2005 Installed. So Don't forget this MinusW -W Ok!? aspnet_regsql.exe -W
After comletting the wizard follow the system orders, maybe you will promted to reboot the system or stuff like that...
then try to run your application once again. using Your, and mine connectionstrings.
...Well :)) if it's still not working, go back to the
* aspnet_regsql.exe
* type: aspnet_regsql.exe -E -A all ..hit enter..
this should anable all the profiles.
If this not working, I think you better explore this tool again and again. and then Go back to your project and try to run it again.
I'm almost sure that the answer is in this tool.
AfterAll Maybe these images will help somehow.
Img1
Img2



Finally If I'll find a straight forward way to fix this problem I'll post back here.
I'm Sure that there's an easy way to fix this.
But I need to make a research my self :( :)
Good Luck Kiley! :)

Read this ScottGu's Talks about this problem!!!!!
  #7 (permalink)  
Old March 8th, 2007, 02:05 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I've tried exactly the instructions above and aspnet_regsql.exe -W opens the wizard.

This is interesting: the wizard's second page asks for Server and it prefils in my computer name "GALACTICA". But this will not connect unless I use "GALACTICA\sqlExpress".

aspnet_regsql.exe -E -A all causes the following error message (in the DOS prompt window (well not DOS but you know))

An error has occurred. Details of the exception:
An error has occurred while establishing a connection ot the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40: - Could not open a connection to SQL Server)

Unable to connect to SQL Server database.

This error is the same one as when I use the ASP.NET SQL Server Setup Wizard but entering only GALACTICA (not GALACTICA\sqlexpress). A "Connection failed" pop-up launches with the same error as above.

I use the MS SQL Server Management Studio Express and it seems I can connect to the database, open the tables and see data. But the .aspx file and the aspnet_regsql.exe command connot connect. This is an out of the box MS SQL 2005 install.

Something else, the .aspx page with the error says:

Cannot open database "Northwind" requested by the login. The login failed.
Login failed for user 'GALACTICA\ASPNET'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Cannot open database "Northwind" requested by the login. The login failed.
Login failed for user 'GALACTICA\ASPNET'.<---- that's not the user I don't think~~~


I get the feeling sql express wont' let connections happen.
Thank you for all your help so far.

Kiley


  #8 (permalink)  
Old March 8th, 2007, 02:42 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

YAY!! Success, it worked!! Your images totally helped (well, so did your other stuff, but the images really got me going)

Here's what I did:

step 1)

in MS SQL Server Management Studio Express:
Security / Logins / 'COMPUTER/ASPNET' / Properties / User Mapping: the Northwind database was not checked. I entered 'COMPUTER/ASPNET' in the USER and had to have 'dbo' in the default Schema (I have no idea what dbo means but i'll look that up later).


This gave me a new error:
Server Error in '/aspTest' Application.
--------------------------------------------------------------------------------

SELECT permission denied on object 'Customers', database 'Northwind', schema 'dbo'.


so I did step 2
step 2)
in MS SQL Server Management Studio Express:
Northwind / properties / permissions: all the check boxes for Grant were deselected except for connect (as a result of step 1). I check the SELECT check box....bingo!

I think I am on my way now!! Yay, on to page 392 of 1410.

Your help was awesome, thank you so much.

Kiley

  #9 (permalink)  
Old March 8th, 2007, 07:42 AM
Authorized User
Points: 176, Level: 3
Points: 176, Level: 3 Points: 176, Level: 3 Points: 176, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Coooooool! You welcome! :))
Ha-ha! I can't believe it's finally working! Great-great!
I'm happy for you! :))
Well... Yep, I do remember that I did something in Management Studio.
I don't know why, but I felt somehow that this problem is related to the Premission stuff inside SQlServer Him self. That's why I decided to show these Images,a specially the Second one,because due to playing with the Management studio I realised that there's a few CheckBoxes(radioButtons) With the GRANT Access premission goin-on. So'a... No comments here!!! :))) I really happy that the problem was solved. :))

****************
Regarding the Previous post,, Yep since you using EXPRESS version
You will need to use this format of log-in
"GALACTICA\sqlExpress".
sometimes it go's just like this: using the Capital letters
"GALACTICA\SQLEXPRESS".

Let me ask you something, since the fix of this problem did your connection string has changed? in the Web.config??
  #10 (permalink)  
Old March 8th, 2007, 01:05 PM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Since I blew away the test site and recreated it, the connnection string has been the same. Well, I renamed the Northwind to shorten it up but otherwise nothing has changed. How come?

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
chapter 11 figure 11-7 relative positioning pelopito BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 November 29th, 2007 06:11 AM
Chapter 11 mhanson BOOK: Professional VB 2005 ISBN: 0-7645-7536-8 0 July 10th, 2007 08:40 PM
Chapter 11 kappa3 Wrox Book Feedback 0 October 8th, 2003 11:21 AM



All times are GMT -4. The time now is 07:04 AM.


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