我可以在任意目录下建这个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) 究竟是什么问题呢?
默认情况下profile provider使用sql server express ,这可以更改以使用sql server 2005来做为你使用profile的数据库.不知道你的机器装有sqlexpress还是sqlserver2005或是两者皆有.
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)
究竟是什么问题呢?
<providers>
<add name="CustomizedProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="ConnectionString"
/>
</providers> <properties>
<add name="Cart"/>
</properties>
</profile>
我自己没具体自定义过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=你建的那个数据库对应的连接字符串名。
直接用cookie或直接写到数据库还省事些