C# ASP.Net在登录时引发错误-在建立与SQL Server的连接时发生与网络相关或特定于实例的错误
我的主机上有一些页面(web表单),可以从MSSQL服务器检索一些信息,并且工作正常,但我的问题是我的“登录”页面。 在我的登录页面中,当用户输入错误的用户名或密码时,表单会正常运行并向用户发送相关消息,但当用户名和密码输入正确时,它会抛出附加的错误 我想这是关于“会员资格”之类的,但我想不出来。这是我的“web.config”文件:C# ASP.Net在登录时引发错误-在建立与SQL Server的连接时发生与网络相关或特定于实例的错误,c#,sql-server,compiler-errors,runtime-error,membership,C#,Sql Server,Compiler Errors,Runtime Error,Membership,我的主机上有一些页面(web表单),可以从MSSQL服务器检索一些信息,并且工作正常,但我的问题是我的“登录”页面。 在我的登录页面中,当用户输入错误的用户名或密码时,表单会正常运行并向用户发送相关消息,但当用户名和密码输入正确时,它会抛出附加的错误 我想这是关于“会员资格”之类的,但我想不出来。这是我的“web.config”文件: <?xml version="1.0"?> <configuration> <configSections> &l
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="JahanPay.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<JahanPay.Properties.Settings>
<setting name="JahanPay_com_jahanpay_Webservice2ControllerService"
serializeAs="String">
<value>http://jahanpay.com/webservice2/index?ws=1</value>
</setting>
</JahanPay.Properties.Settings>
</applicationSettings>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=127.0.0.1;Initial Catalog=ASPNETDB;Integrated Security=False;User ID=something;Password=something;Connect Timeout=15;Encrypt=False;Packet Size=4096" />
</connectionStrings>
<system.web>
<roleManager enabled="true" defaultProvider="SqlProvider" >
<providers>
<clear/>
<add name="SqlProvider" type="System.Web.Security.SqlRoleProvider"
connectionStringName="ConnectionString" applicationName="/" />
</providers>
</roleManager>
<authentication mode="Forms" >
<forms loginUrl="users/signin.aspx" timeout="30"></forms>
</authentication>
<compilation debug="true" targetFramework="4.0"/>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ConnectionString" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" minRequiredNonalphanumericCharacters="0" minRequiredPasswordLength="4" applicationName="/" />
</providers>
</membership>
<profile>
<properties>
<clear/>
<add name="username"/>
<add name="userfamily"/>
<add name="companyname"/>
<add name="sex" type="boolean"/>
<add name="mobile"/>
<add name="birthday" type="DateTime"/>
</properties>
</profile>
<customErrors mode="Off"/>
</system.web>
<location path="userpanel">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="ServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="Service">
<endpoint address="" behaviorConfiguration="ServiceAspNetAjaxBehavior"
binding="webHttpBinding" contract="Service" />
</service>
</services>
</system.serviceModel>
</configuration>
我该怎么办
再次强调,因为我认为这很重要,所以我要指出,只有当用户尝试使用正确的用户名和密码登录时才会发生这种情况。您无法访问sql server。如果通过网络连接,请尝试ping服务器。如果sqlserver应该在您的电脑上,请尝试重新启动sqlserver。正如Knutur0所指出的,错误消息表示它无法访问您的sqlserver
最明显的原因是连接字符串中缺少实例名称。默认情况下,SQL Server作为命名实例安装
请尝试:Data Source=127.0.0.1\SQLEXPRESS
其中SQLEXPRESS是实例名。他已经说过:我的主机上有一些页面(web表单),可以从我的MS-SQL服务器检索一些信息,工作得很好谢谢你的帖子,正如我在帖子中提到的,我的网站在“主机”上另外,我的其他页面正在从SQL Server检索数据,如果您输入了错误的用户名或密码,它会告诉您您做得不对。所以我不这么认为。您的sql连接是在另一台机器上还是在同一台机器上?@Webruster它在共享主机上。我的所有表单(网站)和sql Server都在同一台机器上。初始目录=ASPNETDB,与数据源=127.0.0.1\ASPNETDB相同。但他是对的,你应该检查一下你是否能与给定的信息联系起来。打开sql management studio,尝试与用户sql连接到127.0.0.1,并传递您的web中的连接。配置我的主机上有一些页面(web表单),可以从MS-sql服务器检索一些信息,并且工作正常。这些其他页面是否使用配置文件中指定的连接字符串?@MatthewEvans是的,完全正确!