C# '中的服务器错误/';应用程序(ASP.NET)

C# '中的服务器错误/';应用程序(ASP.NET),c#,asp.net,visual-web-developer,C#,Asp.net,Visual Web Developer,我只是使用msdn教程在我的网站上设置了会员身份角色并注册了VisualWebDeveloper。它在本地运行得非常好,但当我将其上载到服务器时,我会看到以下页面: "Server Error in '/' Application. -------------------------------------------------------------------------------- Configuration Error Description: An error occurred

我只是使用msdn教程在我的网站上设置了会员身份角色并注册了VisualWebDeveloper。它在本地运行得非常好,但当我将其上载到服务器时,我会看到以下页面:

"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',或者连接字符串为空。”。。。并注意到以下元素完全为空:

//这个应该是空的吗?如果不是,这里应该放什么?在错误中,它暗示它不应该为空。另外,我不知道应该将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 

确保在
Web.config
中添加了名为
LocalSqlServer
的连接字符串

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

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


确保在
Web.config
中添加了名为
LocalSqlServer
的连接字符串

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

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


如果您有.Net成员身份角色,请首先查看链接

一些解释,因为你说你不明白

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

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

用SQL db server插件替换DBServerName,用插件附带的数据库名称替换DBName,用SQL插件附带的数据库名称替换DBLogin和密码

如果不想使用LocalSQLSever,可以通过

 <remove name='LocalSqlServer' />


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

如果您有.Net成员身份角色,请首先查看链接

一些解释,因为你说你不明白

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

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

用SQL db server插件替换DBServerName,用插件附带的数据库名称替换DBName,用SQL插件附带的数据库名称替换DBLogin和密码

如果不想使用LocalSQLSever,可以通过

 <remove name='LocalSqlServer' />


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

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

它指向与visual studio一起安装的本地sqlexpress实例

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

如果出于某种原因,您希望使用其他数据库,则必须为其配置aspnet_regsql.exe。您将在windows/microsoft.net/framework/2.0.xxxx目录中找到它

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

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

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

无论哪种方式,您都需要一个已配置的数据库,而不是由开发期间使用的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中的membership部分以指向新数据库


hth

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

它指向与visual studio一起安装的本地sqlexpress实例

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

如果出于某种原因,您希望使用其他数据库,则必须为其配置aspnet_regsql.exe。您将在windows/microsoft.net/framework/2.0.xxxx目录中找到它

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

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

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

无论哪种方式,您都需要配置的数据库而不是本地用户