1

我只是使用 msdn 上的教程在我的网站上使用可视化 Web 开发人员设置了会员角色和注册。它在本地完美运行,但是当我将它上传到我的服务器时,我得到以下页面:

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

Configuration Error 
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.

Source Error: 


[No relevant source lines]


Source File: machine.config    Line: 160 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4200; ASP.NET Version:2.0.50727.4016 "

有谁知道我为什么会看到这个以及如何解决这个问题?任何帮助是极大的赞赏。

谢谢

贝尔。

编辑:

在阅读了错误消息中的以下行后,我刚刚查看了我的 web.config 文件:“在应用程序配置中找不到连接名称‘LocalSqlServer’,或者连接字符串为空。” ...并且注意到以下元素是完全空的:

<connectionStrings/>// 这个应该是空的吗?如果不是什么应该去这里?在错误中,它暗示它不应该为空。另外,我不知道应该在哪里放置 LocalSqlServer

最新编辑

将 DataSource 更改为 LocalHost 后,出现以下错误:

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

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) 
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: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

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: 


[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4849015
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +4862333
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +90
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +342
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +433
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
   System.Data.SqlClient.SqlConnection.Open() +122
   System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +87
   System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +221
   System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Boolean updateLastLoginActivityDate, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved, DateTime& lastLoginDate, DateTime& lastActivityDate) +815
   System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat) +105
   System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved) +42
   System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password) +78
   System.Web.UI.WebControls.Login.AuthenticateUsingMembershipProvider(AuthenticateEventArgs e) +60
   System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e) +119
   System.Web.UI.WebControls.Login.AttemptLogin() +115
   System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +101
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927 
4

6 回答 6

9

确保的. LocalSqlServer_Web.config

如果您使用标准的 ASP.NET Membership/Role 提供程序,默认情况下它们被声明为:

<membership>
  <providers>
    <add
      name="AspNetSqlMembershipProvider"
      type="System.Web.Security.SqlMembershipProvider, ..."
      connectionStringName="LocalSqlServer" ...

connectionStringName是可能导致此错误的原因。如果您计划使用 Membership/Role API,您必须添加一个名为secion 的连接字符串LocalSqlServer,或者更改它以使其值成为有效的(和现有的)连接字符串名称。<connectionString>Web.configconnectionStringAttribute

于 2010-01-20T10:26:31.393 回答
3

如果您有 .Net 成员角色提供者,请先查看链接。

既然你说你不明白,一些解释

网络成员角色提供程序设置为查找“LocalSQLServer”。这意味着我们必须提供名为 LocalSQLServer 的连接的详细信息,或者说它不需要。您可以做的是在您的 web.config 文件中找到该<connectionstrings>部分并添加一行:

<add name='LocalSqlServer' connectionString='Data Source=DBServerName;
Integrated Security=false;Initial Catalog=DBName;
User ID=DBLogin;Password=DBPassword' providerName='System.Data.SqlClient' />

将 DBServerName 替换为您的 SQL 数据库服务器插件,将 DBName 替换为您的插件附带的数据库名称,DBLogin 和 Password 应替换为您的 SQL 插件附带的名称。

如果您不想使用 LocalSQLSever,可以通过以下方式将其删除

 <remove name='LocalSqlServer' />

在属性下的 web.config 文件中。然后将角色提供程序上的连接字符串名称更改为您将使用的连接字符串名称。因此,将现有的连接字符串更改为 name='LocalSQLServer'。

于 2010-01-20T10:28:58.827 回答
3

LocalSqlServer 是 machine.config 中的默认连接字符串条目。尽管不在 app/web 配置文件中,但它始终存在。

它指向与 Visual Studio 一起安装的本地 sqlexpress 实例。

默认情况下,成员资格提供程序在配置时会在您的 app_data 文件夹中创建一个本地 .mdf 文件(单击显示所有文件)。此数据库已配置。

如果出于某种原因您想使用不同的数据库,则必须使用 aspnet_regsql.exe 对其进行配置。您将在 windows/microsoft.net/framework/2.0.xxxx 目录中找到它。

从命令行运行 aspnet_regsql.exe /? 获得指示。

所以..这可能就是您收到这些错误的原因。如果您确实想使用不同的数据库并且不想编辑成员资格部分以指向新数据库,则必须删除 localSqlServer 然后重新添加

或者,再次将您的成员资格元素配置为指向不同的连接。

无论哪种方式,您都需要一个 PROVISIONED 数据库,而不是您在开发期间使用的 VS 提供的本地用户实例以及指向它的连接字符串。

<connectionStrings>
  <remove name='LocalSqlServer' />
  <add name='LocalSqlServer' connectionString='Data Source=DBServerName;
    Integrated Security=false;Initial Catalog=DBName;
    User ID=DBLogin;Password=DBPassword' providerName='System.Data.SqlClient' />
</connectionStrings>

编辑:重读你的问题:

问题是主机没有sql或者不允许用户实例。通常在托管站点中,您将请求一个数据库,并在获得凭据后,使用 aspnet_regsql.exe 来配置该数据库。在这种情况下,您必须修改 web.config 中的成员资格部分以指向您的新数据库。

hth

于 2010-01-26T23:16:33.703 回答
0

为 Microsoft SQL Server 启用命名管道和 TCP/IP

于 2010-01-28T18:18:40.390 回答
0

当 ASPNET 用户对相关框架的配置目录没有读取权限时,我经常看到此消息。在我看来,您的一个键中有一个文件指令,并且框架没有访问权限(通过权限或因为文件不存在)来读取它。

于 2010-01-29T23:39:40.063 回答
0

可能是您从 machine.config 获取连接字符串。摆脱这些而不是使用 remove 的最简单方法是在 connectionstrings 部分中使用自闭合清除元素。

开箱即用的成员资格提供程序应该有一个本地连接字符串条目(新项目默认获取此条目)。您可以创建一个新项目并从那里滑动它。

在服务器上,您需要检查 SQL 是否正确安装,并更新连接字符串以匹配服务器详细信息。

于 2010-01-29T23:36:05.390 回答