asp。net sql 登录

Anglry 2017-10-12 05:56:43
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.IO;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("Demo2.aspx");
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=LENOVO-PC5/MYSQL;Initial Catalog=注册人员名单;User ID=sa;Password=123";
if (conn.State == ConnectionState.Closed){
conn.Open();
} //打开数据库连接
SqlCommand sqlComGet = new SqlCommand(); //创建SqlCommand对象
sqlComGet.Connection = conn; //用sqlCon初始化SqlCommand对象
sqlComGet.CommandText = "select * from TUser where UserName='" + User + "' and UserPwd='" + mm + "'";
SqlDataReader sqlDr = sqlComGet.ExecuteReader(); //创建SqlDataReader对象
if (sqlDr.Read()) //帐号和密码正确
{

Response.Redirect("Demo.aspx");
}
else //帐号或密码错误
{
this.Label1.Text = "您输入的用户名或密码不正确!";
}
conn.Close();
}
}








“/”应用程序中的服务器错误。

找不到网络名。

说明:执行当前Web请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.ComponentModel.Win32Exception:找不到网络名。

源错误:


行 29: conn.ConnectionString = "Data Source=LENOVO-PC5/MYSQL;Initial Catalog=注册人员名单;User ID=sa;Password=123";
行 30: if (conn.State == ConnectionState.Closed){
行 31: conn.Open();
行 32: } //打开数据库连接
行 33: SqlCommand sqlComGet = new SqlCommand(); //创建SqlCommand对象

源文件: e:\程序练习\ Visual Studio 2012 \注册登录\ WebSite8 \ Default.aspx.cs 行: 31

堆栈追踪:


[Win32Exception (0x80004005): 找不到网络名。]

[SqlException (0x80131904): 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - 无法打开到 SQL Server 的连接)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5341687
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +546
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5353471
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +145
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +923
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +311
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +646
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +278
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +732
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +85
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1057
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +196
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +146
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +16
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +94
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +110
System.Data.SqlClient.SqlConnection.Open() +96
_Default.Button1_Click(Object sender, EventArgs e) in e:\程序练习\Visual Studio 2012\注册登录\WebSite8\Default.aspx.cs:31
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628462
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
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) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

版本信息: Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.34274
...全文
544 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
abjba 2017-10-26
  • 打赏
  • 举报
回复
检查服务器是否打开了1433端口。
Go 旅城通票 2017-10-20
  • 打赏
  • 举报
回复
Data Source=LENOVO-PC5/MYSQL 你本机配置为 Data Source=. 注意后面有个点,应该是数据眼出问题了

Web开发学习资料推荐
asp网站使用utf-8编码注意事项
easyui开发技巧
孟子E章 2017-10-13
  • 打赏
  • 举报
回复
出现这样的错误 是数据库连接出现了问题 SQLServer服务没有启动 端口不通 端口被防火墙拦截 数据库服务名称不正确 数据库服务不允许远程访问等原因导致,需要搜索网上的解决办法对照解决
skyblue_bin 2017-10-13
  • 打赏
  • 举报
回复
行 29: conn.ConnectionString = "Data Source=LENOVO-PC5/MYSQL;Initial Catalog=注册人员名单;User ID=sa;Password=123"; 问题原因:数据库没有连接上 29行代码里面,肯定有哪个参数是不对(服务器名称、数据库名称、账号和密码确认是否都是正确的)

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧