c#连sqlserver 2000登陆失败的问题

qingqingliman 2006-03-24 04:19:24
我的环境:VC#.NET2003, 1.1
sQL SERVER 2000
DEBUG运行的错误提示:
用户 'jsf' 登录失败。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Data.SqlClient.SqlException: 用户 'jsf' 登录失败。

源错误:


行 31: if(!Page.IsPostBack)
行 32: {
行 33: sqlDataAdapter1.Fill(dataSet11);
行 34: DataGrid1.DataBind();
行 35: }


源文件: d:\work\sysman\webform1.aspx.cs 行: 33

...全文
178 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
我看你有戏 2006-03-26
  • 打赏
  • 举报
回复
public static SqlConnection CreateDBcon()
{
return new SqlConnection("server = 192.168.0.188,1433;database=DB_date;uid=sa;pwd = 123456;");
}
boy_north 2006-03-26
  • 打赏
  • 举报
回复
首先连接字符串没有写用户密码
再看看你有没有打开连接呀
20011521 2006-03-26
  • 打赏
  • 举报
回复
给jsf所有的权限
happyf101 2006-03-26
  • 打赏
  • 举报
回复
各位搞软件开发(.NET SQL JAVA C++ 等)的朋友有兴趣可能加
18144686
在这里我们真正的做到只讨论技术!
做广告者勿扰!谢谢!
ljhkim6 2006-03-26
  • 打赏
  • 举报
回复
jsf这个用户名添加到了组里没?
你用sa试哈就知道了。
happyf101 2006-03-26
  • 打赏
  • 举报
回复
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=ZHANGGQ;packet size=4096;user id=jsf;data source=\"192.168.1.254\";" +
"persist security info=False;initial catalog=rehpm";
你到服务器上把SQL2000密码确定一下,再一个就是你这个连接没有设置密码
caohblue 2006-03-26
  • 打赏
  • 举报
回复
最简单的连接是:
SqlConnection conn=new SqlConnection("uid=jsf;pwd=;server=.;database=<你的数据库名>");
conn.Open();
然后在SQL SERVER里设置一下jsf的登陆密码,然后在SQL SERVER服务器属性里的安全性选向卡上身份验证选择SQL SERVER和WINDOWS
livode 2006-03-24
  • 打赏
  • 举报
回复
this.sqlConnection1.ConnectionString = "workstation id=ZHANGGQ;packet size=4096;user id=jsf;data source=\"192.168.1.254\";" +
"persist security info=False;initial catalog=rehpm";
--------------------------------------------------------------
就是这句话
jsf的用户密码是你设的阿,就是数据库的用户jsf对应的密码;
在上面的这段代码后面加入下面这段代码:
string passwd = 你的密码;
this.sqlConnection1.ConnectionString = this.sqlConnection1.ConnectionString + ";passwd="+passwd
这是简单的方法,但是这样是很不安全的,这样把密码的名文直接写出来了。
qingqingliman 2006-03-24
  • 打赏
  • 举报
回复
连接语句和密码怎么加啊,


jsf用户的密码是不是1234,要怎么写啊?
qingqingliman 2006-03-24
  • 打赏
  • 举报
回复
它自动生成的啊 ,啊水,你说详细点啊,多谢,我才学C#啊
RUN_ 2006-03-24
  • 打赏
  • 举报
回复
连接语句呢,哪去了。
Knight94 2006-03-24
  • 打赏
  • 举报
回复
this.sqlConnection1.ConnectionString = "workstation id=ZHANGGQ;packet size=4096;user id=jsf;data source=\"192.168.1.254\";" +
"persist security info=False;initial catalog=rehpm";

添加密码
livode 2006-03-24
  • 打赏
  • 举报
回复
登录数据库的密码呢?只有id,没有密码。你怎么能登进去呢.
livode 2006-03-24
  • 打赏
  • 举报
回复
在fill之前,你connect了吗?
qingqingliman 2006-03-24
  • 打赏
  • 举报
回复
接着上面的源代码:
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO country(id, cnname, enname, continent) VALUES (@id, @cnname, @enname," +
" @continent); SELECT id, cnname, enname, continent FROM country WHERE (id = @id)" +
"";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@id", System.Data.SqlDbType.Int, 4, "id"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@cnname", System.Data.SqlDbType.VarChar, 20, "cnname"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@enname", System.Data.SqlDbType.VarChar, 20, "enname"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@continent", System.Data.SqlDbType.VarChar, 10, "continent"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE country SET id = @id, cnname = @cnname, enname = @enname, continent = @continent WHERE (id = @Original_id) AND (cnname = @Original_cnname OR @Original_cnname IS NULL AND cnname IS NULL) AND (continent = @Original_continent OR @Original_continent IS NULL AND continent IS NULL) AND (enname = @Original_enname OR @Original_enname IS NULL AND enname IS NULL); SELECT id, cnname, enname, continent FROM country WHERE (id = @id)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@id", System.Data.SqlDbType.Int, 4, "id"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@cnname", System.Data.SqlDbType.VarChar, 20, "cnname"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@enname", System.Data.SqlDbType.VarChar, 20, "enname"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@continent", System.Data.SqlDbType.VarChar, 10, "continent"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_id", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "id", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_cnname", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "cnname", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_continent", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "continent", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_enname", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "enname", System.Data.DataRowVersion.Original, null));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM country WHERE (id = @Original_id) AND (cnname = @Original_cnname OR @Original_cnname IS NULL AND cnname IS NULL) AND (continent = @Original_continent OR @Original_continent IS NULL AND continent IS NULL) AND (enname = @Original_enname OR @Original_enname IS NULL AND enname IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_id", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "id", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_cnname", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "cnname", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_continent", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "continent", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_enname", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "enname", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=ZHANGGQ;packet size=4096;user id=jsf;data source=\"192.168.1.254\";" +
"persist security info=False;initial catalog=rehpm";

//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();

}
#endregion
}
}
Knight94 2006-03-24
  • 打赏
  • 举报
回复
把你的connectionstring贴出来看看,如果你是用的数据库用户认证的话,如果数据库设置此用户的话,则没有什么问题;如果使用的是系统用户认证的话,则有可能是你的web本身所在的系统无法访问数据库。
qingqingliman 2006-03-24
  • 打赏
  • 举报
回复
以下是源文件
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;

namespace SysMan
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected SysMan.DataSet1 dataSet11;
protected System.Web.UI.WebControls.DataGrid DataGrid1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
sqlDataAdapter1.Fill(dataSet11);
DataGrid1.DataBind();
}
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.dataSet11 = new SysMan.DataSet1();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "country", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("id", "id"),
new System.Data.Common.DataColumnMapping("cnname", "cnname"),
new System.Data.Common.DataColumnMapping("enname", "enname"),
new System.Data.Common.DataColumnMapping("continent", "continent")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT id, cnname, enname, continent FROM country";
this.sqlSelectCommand1.Connection = this.sqlConnection1;

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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