用户登录失败 - > #c到数据库

时间:2015-04-10 18:28:08

标签: c# database authentication

大家好我试图将我的文本框连接到我的数据库" loonberekening table werknemer"

但我收到一个错误名称:用户登录失败

有人能帮帮我吗? 感谢

 private void btnOpslaanwerknemergegevens_Click(object sender, EventArgs e)
    {


        string database = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\gip_stap_2\loonberekening.mdf;Integra‌​ted Security=True;Connect Timeout=30;InitialCatalog=loonberekening";
        string werknemergegevens = "insert into loonberekening.werknemer (naam,voornaam) values ('"+this.txtNaam.Text+"','"+this.txtVoornaam.Text+"');";
        SqlConnection cnnLoonberekening = new SqlConnection(
        @"Data Source=.; AttachDbFilename=|DataDirectory|\loonberekening.mdf;Initial Catalog=loonberekening");
        SqlCommand scmdLoon = new SqlCommand(werknemergegevens, cnnLoonberekening);
        SqlDataReader check;


        try{
            cnnLoonberekening.Open();
            check = scmdLoon.ExecuteReader();
            MessageBox.Show("Opgeslagen");
            while (check.Read())
            {
            }
        }catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

1 个答案:

答案 0 :(得分:0)

我可以问你为什么不这样做 SqlConnection cnnLoonberekening = new SqlConnection(         数据库);

而不是将数据库变量设置为连接字符串,然后再次输入整个事物?数据库字符串变量包含您需要的所有组件。它集成了使用您的Windows ID的安全性,否则您需要将UID = [YourUserNameHere]; PWD [YourPasswordHere]添加到连接字符串。