簡體   English   中英

數據庫到#c(用戶名和密碼)->錯誤

[英]Database to #c (username & password) -> error

我正在學校的一個項目上,但我收到一個錯誤:

“不支持的關鍵字:'集成安全性'”有人可以幫助我嗎?

這是一個圖片: 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);
        }

更改連接中的順序,在集成安全性之前,應該首先是“初始目錄”

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

如果您的數據庫文件附加在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;"

注意:在您的Select Statement使用此loonberekening.dbo.tblInloggen代替此loonberekening.tblInloggen

像這樣

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM