繁体   English   中英

“ /”应用程序(ASP.NET)中的服务器错误

[英]Server Error in '/' Application (ASP.NET)

我只是使用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

最新编辑

将数据源更改为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 

确保您有一个名为连接字符串LocalSqlServer添加的ConnectionStrings你的元素Web.config

如果您使用的是标准ASP.NET成员资格/角色提供程序,则默认情况下将其声明为:

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

可能是导致此错误的是connectionStringName 如果计划使用Membership / Role API,则必须将名为LocalSqlServer的连接字符串添加Web.config <connectionString>部分,或更改connectionStringAttribute以便其值将是有效的(和现有的)连接字符串名称。

如果您具有.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 db服务器附加组件,将DBName替换为附加组件随附的数据库名称,应将DBLogin和Password替换为SQL附加组件随附的组件。

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

 <remove name='LocalSqlServer' />

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

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

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

开箱即用的成员资格提供程序应具有本地连接字符串条目(新项目默认情况下会获得此条目)。 您可以创建一个新项目,然后从那里滑动它。

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

当ASPNET用户没有权限访问有关框架的config目录时,我经常会看到此消息。 在我看来,您在其中一个键中有一个文件指令,并且该框架无权(通过权限或由于文件不存在)来读取它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM