我正在编写代码课程,在SQL部分,是时候运行代码了。我知道这个错误:
System.Data.SqlClient.SqlException:“用户sa登录失败”
错误行在代码中标记。
namespace Zoo_With_SQL
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
SqlConnection sqlConnection;
public MainWindow()
{
InitializeComponent();
string connectionString = ConfigurationManager.ConnectionStrings["Zoo_With_SQL.Properties.Settings.MaydayDBConnectionString"].ConnectionString;
sqlConnection = new SqlConnection(connectionString);
ShowZoos();
}
private void ShowZoos()
{
string query = "select * from Zoo";
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(query, sqlConnection);
using (sqlDataAdapter)
{
DataTable zooTable = new DataTable();
sqlDataAdapter.Fill(zooTable); // Error here!
// What should be shown
ZooList.DisplayMemberPath = "Location";
// Value when selected
ZooList.SelectedValuePath = "Id";
// The reference to use
ZooList.ItemsSource = zooTable.DefaultView;
}
}
}
}我已经完成了大量推荐服务器授权类型的更改。
发布于 2021-02-11 08:19:08
这可能是接收此错误的原因之一,如果您的Server未被配置为使用混合模式身份验证,它实际上不会告诉您这是未启用的!确保启用了混合模式身份验证,下面是如何启用它。


右键单击SQL实例并选择Restart.。
发布于 2021-02-11 04:47:12
请检查连接线。请确保SQL server运行在混合模式身份验证上。
混合模式身份验证:启动>程序> Microsoft >企业管理器
右键单击Server实例名称>从上下文菜单中选择属性>在左侧导航栏中选择安全节点
在“身份验证”部分下,选择Server和Windows身份验证
注意:服务器必须停止并重新启动才能生效。
标准连接字符串:
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;命名实例的连接字符串:
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;Password=myPassword;https://stackoverflow.com/questions/66148440
复制相似问题