如果你建Cart这个库是成功的,查看其中如果有 aspnet_profile即成功添加了这个表.aspnet_profile只是存储profile值的一个容器,具体的profile的名字和值什么的,都需要在web.config中配置.

解决方案 »

  1.   

    我可以在任意目录下建这个profile的表吗?我在C:\Documents and Settings\Zhu\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS这个目录下找到了我所建的数据库Cart。但是当我在.cs文件里用这个表,编译通过了,运行的时候出现了错误如下:
    System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
    究竟是什么问题呢?
      

  2.   

    默认情况下profile provider使用sql server express ,这可以更改以使用sql server 2005来做为你使用profile的数据库.不知道你的机器装有sqlexpress还是sqlserver2005或是两者皆有.
      

  3.   

    <profile defaultProvider="CustomizedProfileProvider" enabled="true">
          <providers>
            <add name="CustomizedProfileProvider"
                 type="System.Web.Profile.SqlProfileProvider"
                 connectionStringName="ConnectionString"
             />
          </providers>      <properties>
            <add name="Cart"/>
                 </properties>
        </profile>
      

  4.   

    可以在web.config里替换默认的ProfileProvider,也就是说可以自定义要访问的Sql Server或Sql Server Express.比如象楼上ymingjun()写的CustomizedProfileProvider就是自定义的ProfileProvider, 注意里面有个connectionStringName="ConnectionString",那个ConnectionString又可以在web.config里的<connectionStrings>里自定义。
    我自己没具体自定义过Profile,以下只供参考:如果要我做,我会在项目的web.config替换默认的Profile Provider,具体配置可以从machine.config.comment里的<profile>段里拷过来,下面这个:<profile enabled="true" defaultProvider="AspNetSqlProfileProvider" inherits="" automaticSaveEnabled="true">
                <providers>
                    <clear />
                    <add connectionStringName="LocalSqlServer" applicationName="/" name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                </providers>
                <properties>
                    <clear />
                </properties>
            </profile>可以看出配置里的connectionStringName="LocalSqlServer"说明它会自动在asp.net项目的App_Code里建aspnet.mdf文件并在那里建表。通过[IIS]->[默认网站]->[属性]->[编辑全局配置]看到LocalServer连接字符串定义是:data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
    (|DataDirectory|可以理解为项目里的App_Code目录)1、用aspnet_sql在需要建表的Sql Express mdf文件里建表,或者在Sql Server。
    2、在你自己的web.config里自定义Profile,最好是起不同于AspNetSqlProfileProvider的名字,然后关键是connectionStringName=你建的那个数据库对应的连接字符串名。
      

  5.   

    petshop4的购物车就是这么做的,比较麻烦要重写个profileprovider
    直接用cookie或直接写到数据库还省事些
      

  6.   

    用javascript+cookie实现购物车功能,而且是AJAX哦
      

  7.   

    我用的 就是 Cookie 和 session 来做的 购物车  但是 感觉 就是很别扭!  有没有谁的 实现代码 发来学习一下!!