'/' 中的服务器错误应用程序(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”或连接字符串为空。 ” ...并且注意到以下元素完全是空的:
// 这个元素应该是空的吗?如果不是,这里应该放什么?在错误中,它暗示它不应该为空。另外,我不知道应该将 LocalSqlServer
LATEST EDIT
放在哪里将 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
I just setup up member ship roles and registration on my website with visual web developer using the tutorial on msdn. It works perfectly locally, but when i uploaded it to my server, I get the following page:
"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 "
Does anybody know why I'm seeing this and how I may go about fixinf this? Any help is greatly appreciated.
Thank you
Bael.
EDIT:
I have just looked at my web.config file after reading the following line in the error message: "The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty." ... And have noticed that the following element is completely empty:
<connectionStrings/>
// Is this one supposed to be empty? if not what should go here? In the error it implies it shouldn't be empty. Also, I don't know where I should place LocalSqlServer
LATEST EDIT
After changing DataSource to LocalHost i get the following error:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
确保添加了名为
LocalSqlServer
的连接字符串 connectionStringsWeb.config 的 a> 元素。如果您使用标准 ASP.NET 成员资格/角色提供程序,则默认情况下它们的声明如下:
connectionStringName
可能会导致此错误。如果您计划使用 Membership/Role API,则必须将名为LocalSqlServer
的连接字符串添加到
部分您的Web.config
,或更改connectionStringAttribute
使其值成为有效(且现有)的连接字符串名称。Ensure you have connection string named
LocalSqlServer
added connectionStrings element of yourWeb.config
.If you're using standard ASP.NET Membership/Role providers, by default they are declared as this:
It's the
connectionStringName
which is likely to be causing this error. If you plan on using Membership/Role API, you'll have to either add a connection string namedLocalSqlServer
to<connectionString>
secion of yourWeb.config
, or changeconnectionStringAttribute
so that its value will be a valid (and existing) connection string name.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,然后重新添加,
或者再次配置您的成员资格元素以指向不同的连接。
无论哪种方式,您都需要一个提供的数据库,而不是您在开发过程中使用的VS提供的本地用户实例以及指向它的连接字符串。
编辑:重新阅读您的问题:
问题是主机没有 sql 或不允许用户实例。通常在托管站点中,您将请求一个数据库,并在获取凭据后,使用 aspnet_regsql.exe 来配置该数据库。在这种情况下,您必须修改 web.config 中的membership 部分以指向您的新数据库。
哈
LocalSqlServer is a default connection string entry in machine.config. It is always present although not in the app/web config file.
It points to your local instance of sqlexpress that was installed with visual studio.
By default the membership provider, upon configuration, creates a local .mdf file in your app_data folder (click show all files). This database has been provisioned.
If for some reason you want to use a different database you must provision it with aspnet_regsql.exe . You will find it in your windows/microsoft.net/framework/2.0.xxxx directory.
from the commandline run aspnet_regsql.exe /? to get instructions.
So.. this may be why you are getting these errors. If you DO want to use a different database and do not want to edit the membership section to point to the new db you must remove localSqlServer and then re-add
OR, again, configure your membership element to point to a different connection.
EITHER WAY you need a PROVISIONED database other than the local user instance that was provisioned by VS that you are using during development and a connection string that points to it.
EDIT: reread your question:
The problem is that the host does not have sql or does not allow user instances. Typically in a hosted site, you will request a database and upon getting the credentials, use aspnet_regsql.exe to provision that database. In this case you MUST modify the membership section in web.config to point to your new database.
hth
如果您有 .Net 会员角色提供程序,请参阅 此链接。
一些解释,因为你说你不明白
网络成员角色提供程序设置为查找“LocalSQLServer”。这意味着我们必须提供名为 LocalSQLServer 的连接的详细信息,或者说不需要它。您可以做的是在 web.config 文件中找到
部分并添加一行:将 DBServerName 替换为您的 SQL 数据库服务器插件,将 DBName 替换为您的插件附带的数据库名称、DBLogin 和密码应替换为 SQL 插件附带的内容。
如果您不想使用 LocalSQLSever,您可以
在 web.config 文件的属性下将其删除。然后将角色提供程序上的连接字符串名称更改为您将使用的连接字符串名称。因此,将现有的连接字符串更改为 name='LocalSQLServer'。
If you have .Net membership roles provider see this link first.
Some explanation since you said you did not understand
Net membership roles provider is setup to look for 'LocalSQLServer'. This means that we have to supply the details for a connection named LocalSQLServer or say it isnt needed. What you can do is in you web.config file find the
<connectionstrings>
part and add a line:Replace the DBServerName with your SQL db server addon, DBName with the database name that came with your addon, DBLogin and Password should be replaced with what came with your SQL addon.
If you don't want to use LocalSQLSever you can remove it by
in your web.config file under the properties. Then change the connection string name on your roles provider to the connection string name you will be using. So change your exisiting connection string to name='LocalSQLServer'.
您可能正在从 machine.config 获取连接字符串。
摆脱这些的最简单方法是在连接字符串部分使用自封闭的清除元素,而不是使用删除。
开箱即用的成员资格提供程序应该有一个本地连接字符串条目(新项目默认情况下会得到这个)。您可以创建一个新项目并从那里滑动它。
在服务器上,您需要检查 SQL 是否安装正确,并更新连接字符串以匹配服务器详细信息。
It may be that you're getting a connection string from the machine.config.
The easiest way to get rid of these, rather than using remove is to use a self closed clear element in the connectionstrings section.
The out of the box membership provider should have had a local connection string entry (new projects get this by default). You could create a new project and swipe it from there.
On the server you'll need to check SQL is installed correctly, and to update the connection string to match the server details.
当 ASPNET 用户没有相关框架的配置目录的读取权限时,我经常看到此消息。在我看来,您的密钥之一中有一个文件指令,并且框架无权读取它(无论是通过权限还是因为文件不存在)。
I've often seen this message when the ASPNET user does not have read access to the config directory for the framework in question. It looks to me like you have a file directive in one of your keys, and the framework does not have access (either through permissions or because the file is not there) to read it.
为 Microsoft SQL 启用命名管道和 TCP/IP服务器
Enable Named Pipes and TCP/IP for Microsoft SQL Server