0

I'm working on a project of school but im getting an error:

"Keyword not supported: 'integrated security'" Can someone help me with this?

Here is a picuture: http://gyazo.com/5a16cde702601e20c811339c01b1911c

Language: Dutch

Code:

 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);
        }
Dabo
  • 2,371
  • 2
  • 18
  • 26
termted
  • 31
  • 1
  • 4

2 Answers2

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");
JC Borlagdan
  • 3,318
  • 5
  • 28
  • 51
0

try this if your database file is attached In SSMS

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

If you want LocalDB automatic instance with specific data file then

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

Note: Use this loonberekening.dbo.tblInloggen instead of this loonberekening.tblInloggen in your Select Statement

Something like this

SqlCommand Selectcommand = 
new SqlCommand("select * from loonberekening.dbo.tblInloggen where id = '" +
 this.txtGebruikersnaam.Text + "' and passwoord= '" + this.txtPaswoord.Text + "' ;", myConn);
Khurram Ali
  • 1,659
  • 4
  • 20
  • 37
  • The second one is working but now im getting this: http://gyazo.com/e6e69199365fdd3674f85a780716ed44 and here is a picture of my database: http://gyazo.com/8e0f827c264e0b0d755d486190224131 dbo.tblInloggen doesnt work also – termted Apr 11 '15 at 15:06
  • @termted try this `loonberekening.dbo.tblInloggen` – Khurram Ali Apr 11 '15 at 15:44
  • loonberekening.dbo.tblInloggen didnt work... :( what do you mean with see edit? – termted Apr 11 '15 at 16:05
  • The string database = @"Server=(localdb)\v11.0;Integrated Security=true; AttachDbFileName=E:\gip_stap_2\loonberekening.mdf;" is working for me and the ("select * from loonberekening.dbo.tblInloggen where id also but now im gettin this error: http://gyazo.com/a08f915d626a2a088dc93bdd03b6061e – termted Apr 11 '15 at 19:36