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

目前我正在开发一个生成文件的项目....()。一切似乎都运作良好。我可以连接到数据库,我的读写方法也可以使用,但是我找不到表。我有一个错误:


$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);

                }


            }

        }

 

PIPIONE
浏览 243回答 1
1回答

慕码人8056858

问题似乎与您传递给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不包含所需表的数据库。
打开App,查看更多内容
随时随地看视频慕课网APP