【问题标题】:Database to #c (username & password) -> error数据库到#c(用户名和密码)-> 错误
【发布时间】:2015-04-11 14:14:05
【问题描述】:

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

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

这是一张图片: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);
        }

【问题讨论】:

  • 您使用的是哪个 RDBMS?
  • SQL 服务器管理工​​作室
  • 您是否将数据库附加到SQL Server Management Studio
  • 试试这个连接字符串 ` Server=(localdb)\v11.0;Integrated Security=true; AttachDbFileName=C:\MyFolder\MyData.mdf;`
  • 作为旁注,您可能想查看parameterised queries,您的查询以这种方式暗示了 SQL 注入。

标签: c# database security integrated


【解决方案1】:

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

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

【讨论】:

  • 它说“关键字不支持:'datasource'”
  • 在数据源之间放置空格
  • 现在我得到这个错误:gyazo.com/5725c180382bf3a88755beaca3a83518(图片)
  • 您使用的是什么版本的 SQL Server?
  • 我认为您的数据库尚未在数据库中创建,或者如果是,您的服务器名称/实例名称不正确。
【解决方案2】:

如果您的数据库文件附加在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);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2018-02-13
  • 1970-01-01
  • 2013-06-03
  • 2016-02-05
  • 2016-12-04
  • 1970-01-01
  • 2012-05-08
  • 2012-08-26
相关资源
最近更新 更多