各位大哥,小弟 最近接触 asp.net 但配置好了后 总是出现这样的情况 望各位哥哥姐姐 告知小弟 不胜感激……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: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
小弟的web 配置是这样的:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="dsn" value="Data Source=mycomputer;UID=sa;PWD=sasasa;DATABASE=WMS"/>
</appSettings>
<system.web>
<customErrors mode="RemoteOnly"/>
<authentication mode="Windows"/>
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"/>
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;user id=sa;password=" cookieless="false" timeout="20"/>
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
<xhtmlConformance mode="Legacy"/></system.web>
</configuration>小弟在线等 谢谢
小弟的web 配置是这样的:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="dsn" value="Data Source=mycomputer;UID=sa;PWD=sasasa;DATABASE=WMS"/>
</appSettings>
<system.web>
<customErrors mode="RemoteOnly"/>
<authentication mode="Windows"/>
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"/>
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;user id=sa;password=" cookieless="false" timeout="20"/>
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
<xhtmlConformance mode="Legacy"/></system.web>
</configuration>小弟在线等 谢谢
缺少服务器的指定 选择本地服务器就行了
sql连接超时了
及时关闭sqlConnection
试试<add key="DBCONNSTR" value="Data Source=192.168.0.1;Initial Catalog=mydb;User ID=sa;Password=sss"/>
sql连接超时了
及时关闭sqlConnection
using,关闭
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>仓库管理系统 |-51aspx.com</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Default" method="post" runat="server">
<table border="1" cellspacing="0" cellpadding="5" align="center" bordercolordark="#cccccc" bordercolorlight="#000000" width="293" height="105">
<tr bgcolor="#cccccc">
<td height="26" align="left" valign="center" bgcolor="#cccccc">
<div align="center"><font size="5">仓库管理系统</font></div>
</td>
</tr>
<tr align="left" valign="center" bgcolor="#ffffff">
<td height="47" valign="top">
<div align="center">
</div>
<div align="center"></div>
<div align="center"></div>
<div align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="36%" style="HEIGHT: 23px">
<div align="right">用户名:</div>
</td>
<td width="64%" style="HEIGHT: 23px">
<asp:TextBox id="tbx_uid" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td width="36%" height="2">
<div align="right">密码:</div>
</td>
<td width="64%" height="2">
<asp:TextBox id="tbx_upassword" runat="server" TextMode="Password"></asp:TextBox></td>
</tr>
</table>
</div>
<asp:Label id="lbl_message" runat="server" ForeColor="Red"></asp:Label>
</td>
</tr>
<tr align="middle" valign="center" bgcolor="#eeeeee">
<td bgcolor="#eeeeee" height="24">
<div align="center">
<asp:Button id="btn_login" runat="server" Text="登入"></asp:Button></div>
</td>
</tr>
</table>
</form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration ;
using System.Data .SqlClient ;namespace WMS
{
//该源码下载自www.51aspx.com(51aspx.com)
/// <summary>
/// _Default 的摘要说明。
/// </summary>
public class _Default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox tbx_uid;
protected System.Web.UI.WebControls.TextBox tbx_upassword;
protected System.Web.UI.WebControls.Label lbl_message;
protected System.Web.UI.WebControls.Button btn_login;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btn_login.Click += new System.EventHandler(this.btn_login_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btn_login_Click(object sender, System.EventArgs e)
{
//从文件Web.config中读取连接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//连接本地计算机的WMS数据库
SqlConnection cn= new SqlConnection (strconn);
cn.Open ();
//构造SQL语句,该语句在Users表中检查用户名和密码是否正确
string mysql= "select * from Users where Uid='"+tbx_uid.Text +"'and UPassword='"+tbx_upassword.Text +"'";
//创建Command对象
SqlCommand cm=new SqlCommand (mysql,cn);
//执行ExecuteReader ()方法
SqlDataReader dr=cm.ExecuteReader ();
if(dr.Read ())
{
lbl_message.Text= "";
//保存当前用户名及用户权限
Session["uid"]=dr["uid"].ToString ();
Session["upower"]=dr["upower"].ToString ();
Session["udep"]=dr["udep"].ToString ();
lbl_message.Text="欢迎您!"+Session["uid"];
if(Session["upower"].ToString ()=="1")
{ //进入仓库总管界面
Response.Redirect ("goodsmanage.aspx");
}
else if(Session["upower"].ToString ()=="2")
{ //进入分仓库管理员界面
Response.Redirect ("goodsreserve.aspx");
}
else if(Session["upower"].ToString ()=="3")
{ //进入仓库采购员界面
Response.Redirect ("orderlist.aspx");
}
}
else
{
lbl_message.Text ="对不起,您的用户名/密码不正确,请重新输入";
}
//关闭连接
cn.Close();
}
}
}
文件如上 望各位 兄弟姐妹 解救 小弟 小弟不胜感激…………………………
用的是ConnectionStrings 节点
private static string connectionString = ConfigurationManager.AppSettings["dsn"].ToString();
用的是AppSettings节点!
按需求选择!