为了账号安全,请及时绑定邮箱和手机立即绑定

C# SQL 连接字符串“找不到表”

C# SQL 连接字符串“找不到表”

C#
PIPIONE 2021-08-22 18:04:23
目前我正在开发一个生成文件的项目....()。一切似乎都运作良好。我可以连接到数据库,我的读写方法也可以使用,但是我找不到表。我有一个错误:$exception {"无效的对象名称 'T_SAL'。"} System.Data.SqlClient.SqlException不知道是我的连接字符串有问题还是别的什么问题!有没有人可以帮我解决这个问题?我的方法代码://SQL连接方法**     public static SqlConnection OpenSql(bool Authentification, string   SQL_LOGIN, string SQL_PASSWORD, string SQL_SERVER, string BASE_CONSOLE)   {        try        {            SqlConnection conn = new SqlConnection();            String Securité;            if (Authentification)            {                Securité = "Integrated Security = true";            }            else    {Securité = "User Id =" + SQL_LOGIN + ";" + "Password =" + SQL_PASSWORD;}       conn.ConnectionString = "Data Source=" + SQL_SERVER + ";Initial Catalog=" + BASE_CONSOLE + ";" + Securité + ";";            conn.Open();            return conn;        }        catch (Exception ex)        {            MessageBox.Show(ex.Message.ToString());            return null;        }// 代:private void Gen_f_Click(object sender, EventArgs e)    {        SqlConnection conn = Methodes.OpenSql(Authentification.Checked, SQL_SERVER.Text, BASE_CONSOLE.Text, SQL_LOGIN.Text, SQL_PASSWORD.Text );        if (conn == null)        {            MessageBox.Show("Connexion impossible");            return;        }        try        {            //traitement du fichier des salaeiés                            var lines = Methodes.lecture(fp_text.Text);            foreach (var ligne in lines)            {                string[] cols = ligne.Split(char.Parse(";"));                                    string Matricule = cols[0];                if (Matricule != "" && MatriculeExiste(conn, Matricule) == false)                {                    string ligneSorties = "";                    ligneSorties = ligneSorties + cols[0] + ";";                    Methodes.Ecriture(ligneSorties, "fp_sorties.'Text'", true);                }            }        } 
查看完整描述

1 回答

?
慕码人8056858

TA贡献1803条经验 获得超6个赞

问题似乎与您传递给OpenSql方法的参数顺序有关:

 public static SqlConnection OpenSql(bool Authentification, string   SQL_LOGIN, string SQL_PASSWORD, string SQL_SERVER, string BASE_CONSOLE)

你是这样称呼它的:

    SqlConnection conn = Methodes.OpenSql(Authentification.Checked, SQL_SERVER.Text, BASE_CONSOLE.Text, SQL_LOGIN.Text, SQL_PASSWORD.Text );

参数顺序肯定有一些不匹配,您的声明需要SQL_Login, SQL_PASSWORD, SQL_SERVER, BASE_CONSOLE并且您正在传递SQL_SERVER, BASE_CONSOLE, SQL_LOGIN, SQL_PASSWORD

因此,如果您使用 Windows 身份验证,它会起作用,因为您没有传递登录名和密码,而是传递了正确的数据库名称,而不是传递密码,因此您的用户最终进入Master不包含所需表的数据库。



查看完整回答
反对 回复 2021-08-22
  • 1 回答
  • 0 关注
  • 242 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信