Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未处理Visual Studio SqlException:用户登录失败';sa';_C#_Sql Server 2012 - Fatal编程技术网

C# 未处理Visual Studio SqlException:用户登录失败';sa';

C# 未处理Visual Studio SqlException:用户登录失败';sa';,c#,sql-server-2012,C#,Sql Server 2012,我有一个非常简单的Windows窗体。我想使用它向数据库添加数据 在我的C#winforms解决方案中,我创建了一个名为db#U studentDataSet的数据源,并连接了我的数据库db#U student。无论何时运行解决方案,都会出现以下异常: SqlException was unhandled: Login failed for user 'sa' 这是我的密码: using System.Drawing; using System.Linq; using System.Text;

我有一个非常简单的Windows窗体。我想使用它向数据库添加数据

在我的C#winforms解决方案中,我创建了一个名为db#U studentDataSet的数据源,并连接了我的数据库db#U student。无论何时运行解决方案,都会出现以下异常:

SqlException was unhandled: Login failed for user 'sa'
这是我的密码:

using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SimpleEnrollmentSystem
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.studentsBindingSource.EndEdit();
            studentsTableAdapter.Insert("Ahmed", "Rownak", "Male", 13, "Malibagh");
        }
    }  

}
这是我表格的一张图片:

这是我的数据库:

  CREATE TABLE Students
  (
      StudentID int primary key,
      FirstName string,
      LastName string,
      Gender string,
      Age int,
      Address string 
  )
请注意,我只为添加按钮功能编写了代码

我的代码有什么问题?还是别的什么?也许我试图实现这一目标的方式是错误的?那样的话,有没有更好的办法

我正在使用Visual Studio 2012 Ultimate和SQL Server 2012 Express Edition

编辑-1:我已更改了我的按钮和单击()方法


根据用户Kiran Hegde的建议,我将连接字符串中的密码更改为明文

  SqlConnection con1 = new SqlConnection("Data Source=SAADMAAN;Initial Catalog=db_student;User ID=sa;Password=open");

这就解决了问题。我太傻了,我跳过了这件显而易见的事

您不认为登录/通过可能是错误的吗?;)据我所知,用户名和密码是正确的。
用户'sa'登录失败。
表示不正确。如何直接登录数据库?您确定要在正确的服务器上访问正确的数据库吗?
sa
是默认的系统管理员用户。不要将其用于您的应用程序。登录失败也可能是因为
sa
用户被禁用(虽然我认为错误可能不同,但不是很确定)。您是否尝试过以明文形式提供密码?
  SqlConnection con1 = new SqlConnection("Data Source=SAADMAAN;Initial Catalog=db_student;User ID=sa;Password=open");