| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1149 人关注过本帖
标题:C# 数据库连接问题
取消只看楼主 加入收藏
yxjcheeryup
Rank: 1
等 级:新手上路
帖 子:3
专家分:2
注 册:2010-8-11
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:0 
C# 数据库连接问题
我是新手,请教下:以下是C#源代码,不知道什么问题,怎么都连接不上数据库..问是在执行了catch里(已标色)了:
 text = login_username.Text;
            key = login_password.Text;
            string str = "user id=sa;password=xjjy287094;";
           //string str="Trusted_Connection=SSPI;";//自动登陆时使用的

           str += @"initial catalog=St_china_elc;Server=(local)\SQL2005;integrated security=True;";
            //str+=@"Server=WWW-9EB2192731B\SQL2005;initial catalog=St_china_elc;Integrated Security=True;";
            str+="Connect Timeout=30";
            // string str=@"Data Source=WWW-9EB2192731B\SQL2005;Initial Catalog=St_china_elc;Integrated Security=True using System;";
            SqlConnection con = new SqlConnection(str);
            try
            {

                con.Open();
                if (con == null)
                {
                    Response.Redirect("PasswordChange.aspx");
                }
                login_username.Text = "hdu";
                login_password.Text = "dj";
               
                string strsql = "select Users_UserName from Users  where Users_UserName=" + login_username.Text + "and Users_Password=" + login_password.Text;
                SqlDataAdapter da = new SqlDataAdapter(strsql, con);
                DataSet ds = new DataSet();
                int count = da.Fill(ds, "table");
                if (count > 0)
                {
                    lab_test1.Visible = true;
                    Response.Redirect("PasswordChange.aspx");

                }
                else
                {
                    Response.Write("<script>alert('<font color=red>不存在的用户名</font>')");
                    lab_test1.Text = "登陆失败";
                    lab_test1.Visible = true;  

                }
            }
            catch (Exception ex)
            {
                lab_test1.Text = "连接\\登陆失败";
                lab_test1.Visible = true;
               
            }

            finally
            {
                login_username.Text = "hdu";
                login_password.Text = "dj";
                con.Close();
            }
        }
搜索更多相关主题的帖子: 数据库 
2010-08-12 11:20
快速回复:C# 数据库连接问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016664 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved