我正在开展一个学校项目,但我得到了一个错误:
"不支持关键字:'集成安全性'" 有人可以帮我这个吗?
以下是图片: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;Integrated 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);
}
答案 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);