2010-01-20 31 views
1

我刚刚在我的网站上使用MSDN上的教程与可视化Web开发人员建立了成员轮船角色和注册。它完美的作品在当地,但是当我把它上传到我的服务器,我进入以下页面:'/'应用程序(ASP.NET)中的服务器错误

"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 " 

有谁知道为什么我看到这一点,我怎么可能去fixinf呢?任何帮助是极大的赞赏。

谢谢

Bael。

编辑:

我刚才看了一下我的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 
+0

你在使用角色提供者吗? – bastijn 2010-01-20 10:34:35

+0

是的,我使用的是角色提供者:) – 2010-01-20 10:40:58

+2

您是否安装了SQL Server? – 2010-01-26 02:26:29

回答

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中的成员资格部分以指向您的新数据库。

心连心

+0

默认情况下,LocalSqlServer在machine.config中定义,但许多主机将删除该条目。 – 2010-01-26 23:30:19

+0

是的,你是对的。 @BAEL - 我已经回答了您关于您的例外的决议的问题。 – 2010-01-28 00:54:14

10

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

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

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

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

+2

不知道你是如何设法从隐晦的错误信息中弄清楚的...... – Paddy 2010-01-20 10:31:20

+1

欲了解更多信息,请参阅https://support.discountasp.net/KB/a337/how-to-configure-aspnet-20- membershiproles-provider.aspx – bastijn 2010-01-20 10:36:46

+0

我很抱歉,但我不冷静理解。我应该添加到connectionsString元素? – 2010-01-20 11:02:10

3

如果您有.Net成员资格角色提供者,请首先参阅this链接。

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

网会员角色提供商的设置,以寻找“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' /> 

与您的SQL数据库服务器插件与你的插件,DBLogin来到数据库名称替换DBSERVERNAME,数据库名密码应该替换为SQL插件随附的内容。

如果你不想使用LocalSQLSever您可以通过

<remove name='LocalSqlServer' /> 

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

+0

谢谢bastijn,我现在想这 – 2010-01-20 11:26:52

+0

谢谢你。它仍然无法正常工作。我不确定你对“插件”的含义是什么? – 2010-01-20 11:32:47

+1

Data Source = localhost,例如,如果您在数据库所在的机器上运行您的站点。我认为如果你使用标准的Windows登录,用户名和密码可以省略。 – bastijn 2010-01-20 12:13:58

0

这可能是因为你得到从machine.config中的连接字符串。 摆脱这些而不是使用remove的最简单方法是在连接字符串部分使用自闭式清除元素。

开箱即用的会员提供商应该有一个本地连接字符串条目(默认情况下,新项目会获得此项)。您可以创建一个新项目并从那里刷卡。

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

0

当ASPNET用户没有读取有关框架的config目录时,我经常看到这条消息。它看起来像你在你的一个关键字中有一个文件指令,并且该框架没有访问权限(通过权限或者因为文件不存在)来读取它。

相关问题