数据库到#c(用户名和密码) - >错误

时间:2015-04-11 14:14:06

标签: c# database security integrated

我正在开展一个学校项目,但我得到了一个错误:

"不支持关键字:'集成安全性'" 有人可以帮我这个吗?

以下是图片: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);
        }

2 个答案:

答案 0 :(得分:0)

更改连接中的顺序,它应该是集成安全性之前的初始目录

SqlConnection con = new SqlConnection(@"DataSource=sadf;Initial Catalog=asdf;Integrated Security=TRUE");

答案 1 :(得分: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.tblInloggen

中使用此loonberekening.tblInloggen代替此Select Statement

像这样的东西

SqlCommand Selectcommand = 
new SqlCommand("select * from loonberekening.dbo.tblInloggen where id = '" +
 this.txtGebruikersnaam.Text + "' and passwoord= '" + this.txtPaswoord.Text + "' ;", myConn);