类库:userdata.dll,其中有数据库连接字符串:Server=localhost;uid=123456;pwd=sa;database=goods该类库在另一项目test中引用
using UserData;问题:当将上述数据库连接字符串中sa密码修改后,在运行项目test时出现“sa登录错误”,是不是因为类库需要重新编译,如何重新编译,请大家帮忙看看。谢谢!!

解决方案 »

  1.   

    Server=localhost;uid=123456;pwd=sa;database=goods你的这个链接字符串写错了吧。。
    Server=localhost;uid=sa;pwd=123456;database=goods用户名是sa 密码123456才对
      

  2.   

    需要把 userdata.dll 的源文件重新编译
      

  3.   

    Server=localhost;uid=sa;pwd=123456;database=goods再重新编译
      

  4.   

    重新编译了userdata.dll还是不行。这是我从网上下载的源码,具体如下:
    D:下有两个文件夹Ltsclient、userdata,其中前一个保存项目文件,后一个为类库,Ltsclient中有一文件loginfrm.cs,代码:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using UserData;namespace LtsClient
    {
    /// <summary>
    /// Form2 的摘要说明。
    /// </summary>
    public class loginFrm : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.TextBox shopname;
    private System.Windows.Forms.TextBox shoppswd;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.Button loginbtn;
    private System.Windows.Forms.Button cancelbtn;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public loginFrm()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.label1 = new System.Windows.Forms.Label();
    this.shopname = new System.Windows.Forms.TextBox();
    this.shoppswd = new System.Windows.Forms.TextBox();
    this.label2 = new System.Windows.Forms.Label();
    this.label3 = new System.Windows.Forms.Label();
    this.loginbtn = new System.Windows.Forms.Button();
    this.cancelbtn = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // label1
    // 
    this.label1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
    this.label1.Location = new System.Drawing.Point(106, 69);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(109, 25);
    this.label1.TabIndex = 0;
    this.label1.Text = "登录系统";
    // 
    // shopname
    // 
    this.shopname.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
    this.shopname.Location = new System.Drawing.Point(114, 103);
    this.shopname.MaxLength = 30;
    this.shopname.Name = "shopname";
    this.shopname.Size = new System.Drawing.Size(109, 21);
    this.shopname.TabIndex = 1;
    this.shopname.Text = "";
    // 
    // shoppswd
    // 
    this.shoppswd.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
    this.shoppswd.Location = new System.Drawing.Point(114, 138);
    this.shoppswd.MaxLength = 30;
    this.shoppswd.Name = "shoppswd";
    this.shoppswd.Size = new System.Drawing.Size(109, 21);
    this.shoppswd.TabIndex = 2;
    this.shoppswd.Text = "";
    // 
    // label2
    // 
    this.label2.Location = new System.Drawing.Point(29, 108);
    this.label2.Name = "label2";
    this.label2.Size = new System.Drawing.Size(77, 17);
    this.label2.TabIndex = 3;
    this.label2.Text = "分店代号";
    // 
    // label3
    // 
    this.label3.Location = new System.Drawing.Point(29, 140);
    this.label3.Name = "label3";
    this.label3.Size = new System.Drawing.Size(77, 17);
    this.label3.TabIndex = 4;
    this.label3.Text = "登录密码";
    // 
    // loginbtn
    // 
    this.loginbtn.Location = new System.Drawing.Point(61, 181);
    this.loginbtn.Name = "loginbtn";
    this.loginbtn.Size = new System.Drawing.Size(83, 25);
    this.loginbtn.TabIndex = 5;
    this.loginbtn.Text = "连接服务器";
    this.loginbtn.Click += new System.EventHandler(this.loginbtn_Click);
    // 
    // cancelbtn
    // 
    this.cancelbtn.Location = new System.Drawing.Point(149, 181);
    this.cancelbtn.Name = "cancelbtn";
    this.cancelbtn.Size = new System.Drawing.Size(83, 25);
    this.cancelbtn.TabIndex = 6;
    this.cancelbtn.Text = "取消连接";
    this.cancelbtn.Click += new System.EventHandler(this.cancelbtn_Click);
    // 
    // loginFrm
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(319, 294);
    this.Controls.Add(this.cancelbtn);
    this.Controls.Add(this.loginbtn);
    this.Controls.Add(this.label3);
    this.Controls.Add(this.label2);
    this.Controls.Add(this.shoppswd);
    this.Controls.Add(this.shopname);
    this.Controls.Add(this.label1);
    this.Name = "loginFrm";
    this.Text = "登录服务器";
    this.ResumeLayout(false); }
    #endregion private void loginbtn_Click(object sender, System.EventArgs e)
    {
    string UserCode=shopname.Text.Trim();
    string UserPswd=shoppswd.Text.Trim();
    if(UserCode=="")
    {
    MessageBox.Show("请输入分店代号");
    }
    else
    {

    SqlDataReader usdr=FPara.SqlReader("select top 1 * from DepartMent where UserID='"+UserCode+"'",FPara.connStr);
    if(usdr!=null){
    if(usdr.Read()){
    if(usdr["Pswd"].ToString()!=UserPswd)
    {
    MessageBox.Show("用户名和密码不相符");
    }
    else{
    FPara.ShopCode=usdr["UserID"].ToString();
    MessageBox.Show("登录成功");
    this.Close();
    }
    }
    usdr.Close();
    }
    }
    } private void cancelbtn_Click(object sender, System.EventArgs e)
    {
    this.Close();
    Application.Exit();
    } }
    }
    文件夹userdata中类库文件userdata.cs:
    using System;
    using System.Data;
    using System.Data.SqlClient;namespace UserData
    {
    public class FPara
    {
    public static string ShopCode="";
    public static bool CheckLogin()
    {
    if(ShopCode=="")
    {
    return false;
    }
    else
    {
    return true;
    }
    }
    public static SqlConnection connStr=new SqlConnection("Server=localhost;uid=sa;pwd=sa;database=goods");
    public static SqlDataReader SqlReader(string sql,SqlConnection connstr)
    {
    SqlDataReader sqldr=null;
    SqlCommand cmd=new SqlCommand(sql,connstr);
    if (cmd.Connection.State.ToString()=="Closed") cmd.Connection.Open();
    try
    {
    sqldr=cmd.ExecuteReader();
    }
    catch(Exception e)
    {
    if (e!=null) sqldr=null;
    }
    return sqldr;
    }
    //数据库操作连接
    public static string SqlCmd(string sql,SqlConnection connstr)
    {
    string errorstr=null;
    SqlCommand sqlcmd= new SqlCommand(sql,connstr);
    if (sqlcmd.Connection.State.ToString()=="Open") sqlcmd.Connection.Close();
    sqlcmd.Connection.Open();
    try
    {
    sqlcmd.ExecuteNonQuery();
    }
    catch(Exception e)
    {
    if (e!=null) errorstr=e.ToString();
    }
    sqlcmd.Connection.Close();
    return errorstr;
    }
    }
    }
    在我本机上SQLSERVER2000的SA密码为sa,我也将类库文件在VS2005的“生成”菜单中进行了“重新生成”,且没出现错误,但在运行项目文件loginfrm.cs时提示在下行中出错“sa登录错误”
    SqlDataReader usdr=FPara.SqlReader("select top 1 * from DepartMent where UserID='"+UserCode+"'",FPara.connStr);
      

  5.   


    Server=localhost;uid=123456;pwd=sa;database=goods你的这个链接字符串写错了吧。。
    Server=localhost;uid=sa;pwd=123456;database=goods用户名是sa 密码123456才对
    -------------------------------------
    很有可能
      
      

  6.   

    Server=localhost;uid=用户名;pwd=密码;database=数据库名重新编译
    在重新引用
      

  7.   

    重新编译后,关键还要重新引用,谢谢liubin911()。