0

我正在做一个学校项目,但我遇到了一个错误:

“不支持关键字:'集成安全'”有人可以帮我解决这个问题吗?

这是一张图片:http: //gyazo.com/5a16cde702601e20c811339c01b1911c

语言:荷兰语

代码:

 private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            string database = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\gip_stap_2\loonberekening.mdf;Integra‌​ted Security=True;Connect Timeout=30;InitialCatalog=loonberekening";
            SqlConnection myConn = new SqlConnection(database);
            SqlCommand Selectcommand = new SqlCommand("select * from loonberekening.tblInloggen where id = '" + this.txtGebruikersnaam.Text + "' and passwoord= '" + this.txtPaswoord.Text + "' ;", myConn);
            SqlDataReader myReader;
            myConn.Open();
            myReader = Selectcommand.ExecuteReader();
            int count = 0;
            while (myReader.Read())
            {
                count = count + 1;
            }
            if (count == 1)
            {
                MessageBox.Show("Gebruikersnaam en paswoord is correct");
                startmenu.ShowDialog();
            }
            else if (count > 1)
            {
                MessageBox.Show("Dit is een gedupliceerde paswoord en gebruikersnaam... Acces verboden");
            }
            else
            {
                MessageBox.Show("Username and paswoord zijn niet correct, Probeer opnieuw");
                myConn.Close();
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
4

2 回答 2

0

Change the order in your connection it should be Initial catalog first before the integrated security

SqlConnection con = new SqlConnection(@"DataSource=sadf;Initial Catalog=asdf;Integrated Security=TRUE");
于 2015-04-11T14:30:14.487 回答
0

如果您的数据库文件附加在中,请尝试此操作SSMS

string database = @"Data Source=.; Integrated Security; 
                  Initial Catalog=loonberekening; Connect Timeout=30;"

如果您想要具有特定数据文件的 LocalDB 自动实例,那么

string database = @"Server=(localdb)\v11.0;Integrated Security=true; 
                  AttachDbFileName=E:\gip_stap_2\loonberekening.mdf;"

注意:loonberekening.dbo.tblInloggenloonberekening.tblInloggenSelect Statement

像这样的东西

SqlCommand Selectcommand = 
new SqlCommand("select * from loonberekening.dbo.tblInloggen where id = '" +
 this.txtGebruikersnaam.Text + "' and passwoord= '" + this.txtPaswoord.Text + "' ;", myConn);
于 2015-04-11T14:34:31.363 回答